public static function convert($value, TypeInterface $type): ?ValueNodeInterface
    {
        if ($type instanceof NonNullType) {
            $node = self::convert($value, $type->getOfType());

            return null !== $node && $node->getKind() === NodeKindEnum::NULL ? null : $node;
        }

        if (null === $value) {
            return new NullValueNode(null);
        }

        // Convert PHP array to GraphQL list. If the GraphQLType is a list, but
        // the value is not an array, convert the value using the list's item type.
        if ($type instanceof ListType) {
            return self::convertListType($value, $type);
        }

        // Populate the fields of the input object by creating ASTs from each value
        // in the PHP object according to the fields in the input type.
        if ($type instanceof InputObjectType) {
            return self::convertInputObjectType($value, $type);
        }

        if ($type instanceof ScalarType || $type instanceof EnumType) {
            return self::convertScalarOrEnum($value, $type);
        }

        throw new ConversionException(\sprintf('Unknown type: %s.', (string)$type));
    }