Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support esm; fix imports #257

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
"js",
"json"
],
"moduleNameMapper": {
"(.+)\\.js": "$1"
},
"testEnvironment": "node",
"testRegex": "(/tests/.*|(\\.|/)test)\\.ts$",
"transform": {
Expand Down
38 changes: 20 additions & 18 deletions src/ast.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
import genFn from "generate-function";
import {
ArgumentNode,
ASTNode,
DirectiveNode,
FieldNode,
FragmentDefinitionNode,
type ArgumentNode,
type ASTNode,
type DirectiveNode,
type FieldNode,
type FragmentDefinitionNode,
getLocation,
GraphQLArgument,
type GraphQLArgument,
GraphQLDirective,
GraphQLError,
GraphQLField,
type GraphQLField,
GraphQLIncludeDirective,
GraphQLInputType,
type GraphQLInputType,
GraphQLObjectType,
GraphQLSkipDirective,
InlineFragmentNode,
type InlineFragmentNode,
isEnumType,
isInputObjectType,
isListType,
isNonNullType,
isScalarType,
print,
SelectionSetNode,
SourceLocation,
type SelectionSetNode,
type SourceLocation,
typeFromAST,
valueFromASTUntyped,
ValueNode,
VariableNode
type ValueNode,
type VariableNode,
Kind,
type SelectionNode,
type TypeNode,
isAbstractType
} from "graphql";
import { Kind, SelectionNode, TypeNode } from "graphql/language";
import { isAbstractType } from "graphql/type";
import { CompilationContext, GLOBAL_VARIABLES_NAME } from "./execution";
import createInspect from "./inspect";
import { getGraphQLErrorOptions, resolveFieldDef } from "./compat";
import { type CompilationContext, GLOBAL_VARIABLES_NAME } from "./execution.js";
import createInspect from "./inspect.js";
import { getGraphQLErrorOptions, resolveFieldDef } from "./compat.js";

export interface JitFieldNode extends FieldNode {
/**
Expand Down
22 changes: 11 additions & 11 deletions src/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import {
GraphQLSchema,
GraphQLError,
versionInfo,
FieldNode,
GraphQLField
type FieldNode,
type GraphQLField,
type ASTNode,
type OperationDefinitionNode,
type GraphQLObjectType,
type GraphQLFormattedError
} from "graphql";
import { GraphQLObjectType } from "graphql/type/definition";
import { Maybe } from "graphql/jsutils/Maybe";

import { ASTNode, OperationDefinitionNode } from "graphql/language/ast";
import * as errorUtilities from "graphql/error";
import * as utilities from "graphql/utilities";
import { GraphQLFormattedError } from "graphql/error";
import { CompilationContext } from "./execution";
import * as execute from "graphql/execution/execute";
import { type Maybe } from "./types.js";
import * as errorUtilities from "graphql/error/index.js";
import * as utilities from "graphql/utilities/index.js";
import { type CompilationContext } from "./execution.js";
import * as execute from "graphql/execution/execute.js";

/**
* A helper file to support backward compatibility for different versions of graphql-js.
Expand Down
5 changes: 4 additions & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* Based on https://github.com/graphql/graphql-js/blob/master/src/error/GraphQLError.js
*/

import { GraphQLError as UpstreamGraphQLError, SourceLocation } from "graphql";
import {
GraphQLError as UpstreamGraphQLError,
type SourceLocation
} from "graphql";

export function GraphQLError(
message: string,
Expand Down
67 changes: 34 additions & 33 deletions src/execution.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { TypedDocumentNode } from "@graphql-typed-document-node/core";
import { type TypedDocumentNode } from "@graphql-typed-document-node/core";
import fastJson from "fast-json-stringify";
import genFn from "generate-function";
import {
ASTNode,
DocumentNode,
ExecutionResult,
FragmentDefinitionNode,
GraphQLAbstractType,
type ASTNode,
type DocumentNode,
type ExecutionResult,
type FragmentDefinitionNode,
type GraphQLAbstractType,
GraphQLEnumType,
GraphQLError,
GraphQLFieldResolver,
GraphQLIsTypeOfFn,
GraphQLLeafType,
type GraphQLFieldResolver,
type GraphQLIsTypeOfFn,
type GraphQLLeafType,
GraphQLList,
GraphQLObjectType,
GraphQLOutputType,
GraphQLResolveInfo,
GraphQLScalarSerializer,
type GraphQLOutputType,
type GraphQLResolveInfo,
type GraphQLScalarSerializer,
GraphQLScalarType,
GraphQLSchema,
GraphQLType,
type GraphQLType,
isAbstractType,
isLeafType,
isListType,
Expand All @@ -28,42 +28,43 @@ import {
isSpecifiedScalarType,
Kind,
locatedError,
TypeNameMetaFieldDef
TypeNameMetaFieldDef,
type FieldNode,
type OperationDefinitionNode,
type GraphQLTypeResolver
} from "graphql";
import { ExecutionContext as GraphQLContext } from "graphql/execution/execute";
import { pathToArray } from "graphql/jsutils/Path";
import { FieldNode, OperationDefinitionNode } from "graphql/language/ast";
import { GraphQLTypeResolver } from "graphql/type/definition";
import { type ExecutionContext as GraphQLContext } from "graphql/execution/execute.js";
import { pathToArray } from "graphql/jsutils/Path.js";
import {
addPath,
Arguments,
type Arguments,
collectFields,
collectSubfields,
computeLocations,
FieldsAndNodes,
type FieldsAndNodes,
flattenPath,
getArgumentDefs,
JitFieldNode,
type JitFieldNode,
joinSkipIncludePath,
ObjectPath,
type ObjectPath,
resolveFieldDef,
serializeObjectPathForSkipInclude
} from "./ast";
import { GraphQLError as GraphqlJitError } from "./error";
import createInspect from "./inspect";
import { queryToJSONSchema } from "./json";
import { createNullTrimmer, NullTrimmer } from "./non-null";
} from "./ast.js";
import { GraphQLError as GraphqlJitError } from "./error.js";
import createInspect from "./inspect.js";
import { queryToJSONSchema } from "./json.js";
import { createNullTrimmer, type NullTrimmer } from "./non-null.js";
import {
createResolveInfoThunk,
ResolveInfoEnricherInput
} from "./resolve-info";
import { Maybe } from "./types";
type ResolveInfoEnricherInput
} from "./resolve-info.js";
import { type Maybe } from "./types.js";
import {
CoercedVariableValues,
type CoercedVariableValues,
compileVariableParsing,
failToParseVariables
} from "./variables";
import { getGraphQLErrorOptions, getOperationRootType } from "./compat";
} from "./variables.js";
import { getGraphQLErrorOptions, getOperationRootType } from "./compat.js";

const inspect = createInspect();

Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export {
compileQuery,
isCompiledQuery,
CompilerOptions,
CompiledQuery
} from "./execution";
type CompilerOptions,
type CompiledQuery
} from "./execution.js";

export {
GraphQLJitResolveInfo,
FieldExpansion,
LeafField,
TypeExpansion,
type GraphQLJitResolveInfo,
type FieldExpansion,
type LeafField,
type TypeExpansion,
fieldExpansionEnricher,
isLeafField,
ResolveInfoEnricherInput
} from "./resolve-info";
type ResolveInfoEnricherInput
} from "./resolve-info.js";
24 changes: 12 additions & 12 deletions src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @type {<type>}
*/
import {
FieldNode,
GraphQLType,
type FieldNode,
type GraphQLType,
isAbstractType,
isEnumType,
isListType,
Expand All @@ -14,17 +14,17 @@ import {
isScalarType
} from "graphql";
import {
BooleanSchema,
IntegerSchema,
NumberSchema,
ObjectSchema,
RefSchema,
Schema,
StringSchema
type BooleanSchema,
type IntegerSchema,
type NumberSchema,
type ObjectSchema,
type RefSchema,
type Schema,
type StringSchema
} from "fast-json-stringify";
import { collectFields, collectSubfields, resolveFieldDef } from "./ast";
import { getOperationRootType } from "./compat";
import { CompilationContext } from "./execution";
import { collectFields, collectSubfields, resolveFieldDef } from "./ast.js";
import { getOperationRootType } from "./compat.js";
import { type CompilationContext } from "./execution.js";

const PRIMITIVES: {
[key: string]:
Expand Down
18 changes: 9 additions & 9 deletions src/non-null.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
ExecutionResult,
FieldNode,
GraphQLError,
GraphQLType,
type ExecutionResult,
type FieldNode,
type GraphQLError,
type GraphQLType,
isListType,
isNonNullType,
isObjectType
isObjectType,
isAbstractType
} from "graphql";
import { isAbstractType } from "graphql/type";
import merge from "lodash.merge";
import { collectFields, collectSubfields, resolveFieldDef } from "./ast";
import { getOperationRootType } from "./compat";
import { CompilationContext } from "./execution";
import { collectFields, collectSubfields, resolveFieldDef } from "./ast.js";
import { getOperationRootType } from "./compat.js";
import { type CompilationContext } from "./execution.js";

interface QueryMetadata {
isNullable: boolean;
Expand Down
14 changes: 7 additions & 7 deletions src/resolve-info.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import genFn from "generate-function";
import {
doTypesOverlap,
FieldNode,
GraphQLCompositeType,
type FieldNode,
type GraphQLCompositeType,
GraphQLError,
GraphQLInterfaceType,
GraphQLNamedType,
type GraphQLNamedType,
GraphQLObjectType,
GraphQLOutputType,
GraphQLResolveInfo,
type GraphQLOutputType,
type GraphQLResolveInfo,
GraphQLSchema,
isAbstractType,
isCompositeType,
Expand All @@ -17,11 +17,11 @@ import {
isObjectType,
isUnionType,
Kind,
SelectionSetNode
type SelectionSetNode
} from "graphql";
import memoize from "lodash.memoize";
import mergeWith from "lodash.mergewith";
import { memoize2, memoize4 } from "./memoize";
import { memoize2, memoize4 } from "./memoize.js";

// TODO(boopathi): Use negated types to express
// Enrichments<T> = { [key in (string & not keyof GraphQLResolveInfo)]: T[key] }
Expand Down
12 changes: 6 additions & 6 deletions src/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
GraphQLError,
GraphQLFloat,
GraphQLID,
GraphQLInputType,
type GraphQLInputType,
GraphQLInt,
GraphQLSchema,
GraphQLString,
Expand All @@ -14,14 +14,14 @@ import {
isNonNullType,
isScalarType,
print,
SourceLocation,
type SourceLocation,
typeFromAST,
valueFromAST,
VariableDefinitionNode
type VariableDefinitionNode
} from "graphql";
import { addPath, computeLocations, ObjectPath } from "./ast";
import { GraphQLError as GraphQLJITError } from "./error";
import createInspect from "./inspect";
import { addPath, computeLocations, type ObjectPath } from "./ast.js";
import { GraphQLError as GraphQLJITError } from "./error.js";
import createInspect from "./inspect.js";

const inspect = createInspect();

Expand Down