diff --git a/src/execution/execute.js b/src/execution/execute.js index f6f6144359..804c41ac8c 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -423,7 +423,7 @@ function executeOperation( */ function executeFieldsSerially( exeContext: ExecutionContext, - parentType: GraphQLObjectType, + parentType: GraphQLObjectType<*, *>, sourceValue: mixed, path: ResponsePath | void, fields: ObjMap>, @@ -462,7 +462,7 @@ function executeFieldsSerially( */ function executeFields( exeContext: ExecutionContext, - parentType: GraphQLObjectType, + parentType: GraphQLObjectType<*, *>, sourceValue: mixed, path: ResponsePath | void, fields: ObjMap>, @@ -511,7 +511,7 @@ function executeFields( */ export function collectFields( exeContext: ExecutionContext, - runtimeType: GraphQLObjectType, + runtimeType: GraphQLObjectType<*, *>, selectionSet: SelectionSetNode, fields: ObjMap>, visitedFragmentNames: ObjMap, @@ -607,7 +607,7 @@ function shouldIncludeNode( function doesFragmentConditionMatch( exeContext: ExecutionContext, fragment: FragmentDefinitionNode | InlineFragmentNode, - type: GraphQLObjectType, + type: GraphQLObjectType<*, *>, ): boolean { const typeConditionNode = fragment.typeCondition; if (!typeConditionNode) { @@ -638,7 +638,7 @@ function getFieldEntryKey(node: FieldNode): string { */ function resolveField( exeContext: ExecutionContext, - parentType: GraphQLObjectType, + parentType: GraphQLObjectType<*, *>, source: mixed, fieldNodes: $ReadOnlyArray, path: ResponsePath, @@ -686,7 +686,7 @@ export function buildResolveInfo( exeContext: ExecutionContext, fieldDef: GraphQLField<*, *>, fieldNodes: $ReadOnlyArray, - parentType: GraphQLObjectType, + parentType: GraphQLObjectType<*, *>, path: ResponsePath, ): GraphQLResolveInfo { // The resolve function's optional fourth argument is a collection of @@ -1030,13 +1030,13 @@ function completeAbstractValue( } function ensureValidRuntimeType( - runtimeTypeOrName: ?GraphQLObjectType | string, + runtimeTypeOrName: ?GraphQLObjectType<*, *> | string, exeContext: ExecutionContext, returnType: GraphQLAbstractType, fieldNodes: $ReadOnlyArray, info: GraphQLResolveInfo, result: mixed, -): GraphQLObjectType { +): GraphQLObjectType<*, *> { const runtimeType = typeof runtimeTypeOrName === 'string' ? exeContext.schema.getType(runtimeTypeOrName) @@ -1069,7 +1069,7 @@ function ensureValidRuntimeType( */ function completeObjectValue( exeContext: ExecutionContext, - returnType: GraphQLObjectType, + returnType: GraphQLObjectType<*, *>, fieldNodes: $ReadOnlyArray, info: GraphQLResolveInfo, path: ResponsePath, @@ -1111,7 +1111,7 @@ function completeObjectValue( } function invalidReturnTypeError( - returnType: GraphQLObjectType, + returnType: GraphQLObjectType<*, *>, result: mixed, fieldNodes: $ReadOnlyArray, ): GraphQLError { @@ -1123,7 +1123,7 @@ function invalidReturnTypeError( function collectAndExecuteSubfields( exeContext: ExecutionContext, - returnType: GraphQLObjectType, + returnType: GraphQLObjectType<*, *>, fieldNodes: $ReadOnlyArray, path: ResponsePath, result: mixed, @@ -1141,7 +1141,7 @@ function collectAndExecuteSubfields( const collectSubfields = memoize3(_collectSubfields); function _collectSubfields( exeContext: ExecutionContext, - returnType: GraphQLObjectType, + returnType: GraphQLObjectType<*, *>, fieldNodes: $ReadOnlyArray, ): ObjMap> { let subFieldNodes = Object.create(null); @@ -1176,7 +1176,7 @@ function defaultResolveTypeFn( contextValue: mixed, info: GraphQLResolveInfo, abstractType: GraphQLAbstractType, -): MaybePromise { +): MaybePromise | string> { // First, look for `__typename`. if ( value !== null && @@ -1248,7 +1248,7 @@ export const defaultFieldResolver: GraphQLFieldResolver = function( */ export function getFieldDef( schema: GraphQLSchema, - parentType: GraphQLObjectType, + parentType: GraphQLObjectType<*, *>, fieldName: string, ): ?GraphQLField<*, *> { if ( diff --git a/src/type/definition.js b/src/type/definition.js index 675092d0a7..be347a9542 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -46,8 +46,8 @@ import type { MaybePromise } from '../jsutils/MaybePromise'; * These are all of the possible kinds of types. */ export type GraphQLType = - | GraphQLScalarType - | GraphQLObjectType + | GraphQLScalarType<*, *> + | GraphQLObjectType<*, *> | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType @@ -84,7 +84,7 @@ export function isScalarType(type) { return instanceOf(type, GraphQLScalarType); } -export function assertScalarType(type: mixed): GraphQLScalarType { +export function assertScalarType(type: mixed): GraphQLScalarType<*, *> { invariant( isScalarType(type), `Expected ${inspect(type)} to be a GraphQL Scalar type.`, @@ -99,7 +99,7 @@ export function isObjectType(type) { return instanceOf(type, GraphQLObjectType); } -export function assertObjectType(type: mixed): GraphQLObjectType { +export function assertObjectType(type: mixed): GraphQLObjectType<*, *> { invariant( isObjectType(type), `Expected ${inspect(type)} to be a GraphQL Object type.`, @@ -201,12 +201,12 @@ export function assertNonNullType(type: mixed): GraphQLNonNull { * These types may be used as input types for arguments and directives. */ export type GraphQLInputType = - | GraphQLScalarType + | GraphQLScalarType<*, *> | GraphQLEnumType | GraphQLInputObjectType | GraphQLList | GraphQLNonNull< - | GraphQLScalarType + | GraphQLScalarType<*, *> | GraphQLEnumType | GraphQLInputObjectType | GraphQLList, @@ -233,15 +233,15 @@ export function assertInputType(type: mixed): GraphQLInputType { * These types may be used as output types as the result of fields. */ export type GraphQLOutputType = - | GraphQLScalarType - | GraphQLObjectType + | GraphQLScalarType<*, *> + | GraphQLObjectType<*, *> | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType | GraphQLList | GraphQLNonNull< - | GraphQLScalarType - | GraphQLObjectType + | GraphQLScalarType<*, *> + | GraphQLObjectType<*, *> | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType @@ -270,7 +270,7 @@ export function assertOutputType(type: mixed): GraphQLOutputType { /** * These types may describe types which may be leaf values. */ -export type GraphQLLeafType = GraphQLScalarType | GraphQLEnumType; +export type GraphQLLeafType = GraphQLScalarType<*, *> | GraphQLEnumType; export function isLeafType(type: mixed): boolean %checks { return isScalarType(type) || isEnumType(type); @@ -288,7 +288,7 @@ export function assertLeafType(type: mixed): GraphQLLeafType { * These types may describe the parent context of a selection set. */ export type GraphQLCompositeType = - | GraphQLObjectType + | GraphQLObjectType<*, *> | GraphQLInterfaceType | GraphQLUnionType; @@ -423,8 +423,8 @@ export function assertWrappingType(type: mixed): GraphQLWrappingType { * These types can all accept null as a value. */ export type GraphQLNullableType = - | GraphQLScalarType - | GraphQLObjectType + | GraphQLScalarType<*, *> + | GraphQLObjectType<*, *> | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType @@ -458,8 +458,8 @@ export function getNullableType(type) { * These named types do not include modifiers like List or NonNull. */ export type GraphQLNamedType = - | GraphQLScalarType - | GraphQLObjectType + | GraphQLScalarType + | GraphQLObjectType<*, *> | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType @@ -532,21 +532,21 @@ function resolveThunk<+T>(thunk: Thunk): T { * }); * */ -export class GraphQLScalarType { +export class GraphQLScalarType { name: string; description: ?string; - serialize: GraphQLScalarSerializer<*>; - parseValue: GraphQLScalarValueParser<*>; - parseLiteral: GraphQLScalarLiteralParser<*>; + serialize: GraphQLScalarSerializer; + parseValue: GraphQLScalarValueParser; + parseLiteral: GraphQLScalarLiteralParser; astNode: ?ScalarTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; - constructor(config: GraphQLScalarTypeConfig<*, *>): void { + constructor(config: GraphQLScalarTypeConfig): void { this.name = config.name; this.description = config.description; this.serialize = config.serialize; - this.parseValue = config.parseValue || (value => value); - this.parseLiteral = config.parseLiteral || valueFromASTUntyped; + this.parseValue = config.parseValue || ((value): TInternal => (value: any)); + this.parseLiteral = config.parseLiteral || (valueFromASTUntyped: GraphQLScalarLiteralParser = {| * }); * */ -export class GraphQLObjectType { +export class GraphQLObjectType { name: string; description: ?string; astNode: ?ObjectTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; - isTypeOf: ?GraphQLIsTypeOfFn<*, *>; + isTypeOf: ?GraphQLIsTypeOfFn; - _fields: Thunk>; + _fields: Thunk>; _interfaces: Thunk>; - constructor(config: GraphQLObjectTypeConfig<*, *>): void { + constructor(config: GraphQLObjectTypeConfig): void { this.name = config.name; this.description = config.description; this.astNode = config.astNode; @@ -681,8 +681,8 @@ export class GraphQLObjectType { defineToStringTag(GraphQLObjectType); defineToJSON(GraphQLObjectType); -function defineInterfaces( - config: GraphQLObjectTypeConfig<*, *>, +function defineInterfaces( + config: GraphQLObjectTypeConfig, ): Array { const interfaces = resolveThunk(config.interfaces) || []; invariant( @@ -770,7 +770,7 @@ export type GraphQLTypeResolver = ( value: TSource, context: TContext, info: GraphQLResolveInfo, -) => MaybePromise; +) => MaybePromise | string>; export type GraphQLIsTypeOfFn = ( source: TSource, @@ -793,7 +793,7 @@ export type GraphQLResolveInfo = {| +fieldName: string, +fieldNodes: $ReadOnlyArray, +returnType: GraphQLOutputType, - +parentType: GraphQLObjectType, + +parentType: GraphQLObjectType<*, *>, +path: ResponsePath, +schema: GraphQLSchema, +fragments: ObjMap, @@ -968,7 +968,7 @@ export class GraphQLUnionType { extensionASTNodes: ?$ReadOnlyArray; resolveType: ?GraphQLTypeResolver<*, *>; - _types: Thunk>; + _types: Thunk>>; constructor(config: GraphQLUnionTypeConfig<*, *>): void { this.name = config.name; @@ -985,7 +985,7 @@ export class GraphQLUnionType { ); } - getTypes(): Array { + getTypes(): Array> { if (typeof this._types === 'function') { this._types = this._types(); } @@ -1003,7 +1003,7 @@ defineToJSON(GraphQLUnionType); function defineTypes( config: GraphQLUnionTypeConfig<*, *>, -): Array { +): Array> { const types = resolveThunk(config.types) || []; invariant( Array.isArray(types), @@ -1015,7 +1015,7 @@ function defineTypes( export type GraphQLUnionTypeConfig = {| name: string, - types: Thunk>, + types: Thunk>>, /** * Optionally provide a custom type resolver function. If one is not provided, * the default implementation will call `isTypeOf` on each implementing diff --git a/src/type/scalars.js b/src/type/scalars.js index 89f6ed252b..f184d95074 100644 --- a/src/type/scalars.js +++ b/src/type/scalars.js @@ -58,7 +58,7 @@ function coerceInt(value: mixed): number { return value; } -export const GraphQLInt = new GraphQLScalarType({ +export const GraphQLInt = new GraphQLScalarType({ name: 'Int', description: 'The `Int` scalar type represents non-fractional signed whole numeric ' + @@ -102,7 +102,7 @@ function coerceFloat(value: mixed): number { return value; } -export const GraphQLFloat = new GraphQLScalarType({ +export const GraphQLFloat = new GraphQLScalarType({ name: 'Float', description: 'The `Float` scalar type represents signed double-precision fractional ' + @@ -214,7 +214,7 @@ function coerceID(value: mixed): string { throw new TypeError(`ID cannot represent value: ${inspect(value)}`); } -export const GraphQLID = new GraphQLScalarType({ +export const GraphQLID = new GraphQLScalarType({ name: 'ID', description: 'The `ID` scalar type represents a unique identifier, often used to ' + diff --git a/src/type/schema.js b/src/type/schema.js index ad95d34a32..018ec9b6a7 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -79,12 +79,12 @@ export function isSchema(schema) { export class GraphQLSchema { astNode: ?SchemaDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; - _queryType: ?GraphQLObjectType; - _mutationType: ?GraphQLObjectType; - _subscriptionType: ?GraphQLObjectType; + _queryType: ?GraphQLObjectType<*, *>; + _mutationType: ?GraphQLObjectType<*, *>; + _subscriptionType: ?GraphQLObjectType<*, *>; _directives: $ReadOnlyArray; _typeMap: TypeMap; - _implementations: ObjMap>; + _implementations: ObjMap>>; _possibleTypeMap: ?ObjMap>; // Used as a cache for validateSchema(). __validationErrors: ?$ReadOnlyArray; @@ -174,15 +174,15 @@ export class GraphQLSchema { } } - getQueryType(): ?GraphQLObjectType { + getQueryType(): ?GraphQLObjectType<*, *> { return this._queryType; } - getMutationType(): ?GraphQLObjectType { + getMutationType(): ?GraphQLObjectType<*, *> { return this._mutationType; } - getSubscriptionType(): ?GraphQLObjectType { + getSubscriptionType(): ?GraphQLObjectType<*, *> { return this._subscriptionType; } @@ -196,7 +196,7 @@ export class GraphQLSchema { getPossibleTypes( abstractType: GraphQLAbstractType, - ): $ReadOnlyArray { + ): $ReadOnlyArray> { if (isUnionType(abstractType)) { return abstractType.getTypes(); } @@ -205,7 +205,7 @@ export class GraphQLSchema { isPossibleType( abstractType: GraphQLAbstractType, - possibleType: GraphQLObjectType, + possibleType: GraphQLObjectType<*, *>, ): boolean { let possibleTypeMap = this._possibleTypeMap; if (!possibleTypeMap) { @@ -258,9 +258,9 @@ export type GraphQLSchemaValidationOptions = {| |}; export type GraphQLSchemaConfig = {| - query?: ?GraphQLObjectType, - mutation?: ?GraphQLObjectType, - subscription?: ?GraphQLObjectType, + query?: ?GraphQLObjectType<*, *>, + mutation?: ?GraphQLObjectType<*, *>, + subscription?: ?GraphQLObjectType<*, *>, types?: ?Array, directives?: ?Array, astNode?: ?SchemaDefinitionNode, diff --git a/src/type/validate.js b/src/type/validate.js index 22f3423d58..4a5108990a 100644 --- a/src/type/validate.js +++ b/src/type/validate.js @@ -152,7 +152,7 @@ function validateRootTypes(context) { function getOperationTypeNode( schema: GraphQLSchema, - type: GraphQLObjectType, + type: GraphQLObjectType<*, *>, operation: string, ): ?ASTNode { const operationNodes = getAllSubNodes(schema, node => node.operationTypes); @@ -268,7 +268,7 @@ function validateTypes(context: SchemaValidationContext): void { function validateFields( context: SchemaValidationContext, - type: GraphQLObjectType | GraphQLInterfaceType, + type: GraphQLObjectType<*, *> | GraphQLInterfaceType, ): void { const fields = objectValues(type.getFields()); @@ -335,7 +335,7 @@ function validateFields( function validateObjectInterfaces( context: SchemaValidationContext, - object: GraphQLObjectType, + object: GraphQLObjectType<*, *>, ): void { const implementedTypeNames = Object.create(null); for (const iface of object.getInterfaces()) { @@ -362,7 +362,7 @@ function validateObjectInterfaces( function validateObjectImplementsInterface( context: SchemaValidationContext, - object: GraphQLObjectType, + object: GraphQLObjectType<*, *>, iface: GraphQLInterfaceType, ): void { const objectFieldMap = object.getFields(); @@ -587,14 +587,14 @@ function getAllSubNodes( } function getImplementsInterfaceNode( - type: GraphQLObjectType, + type: GraphQLObjectType<*, *>, iface: GraphQLInterfaceType, ): ?NamedTypeNode { return getAllImplementsInterfaceNodes(type, iface)[0]; } function getAllImplementsInterfaceNodes( - type: GraphQLObjectType, + type: GraphQLObjectType<*, *>, iface: GraphQLInterfaceType, ): $ReadOnlyArray { return getAllSubNodes(type, typeNode => typeNode.interfaces).filter( @@ -603,14 +603,14 @@ function getAllImplementsInterfaceNodes( } function getFieldNode( - type: GraphQLObjectType | GraphQLInterfaceType, + type: GraphQLObjectType<*, *> | GraphQLInterfaceType, fieldName: string, ): ?FieldDefinitionNode { return getAllFieldNodes(type, fieldName)[0]; } function getAllFieldNodes( - type: GraphQLObjectType | GraphQLInterfaceType, + type: GraphQLObjectType<*, *> | GraphQLInterfaceType, fieldName: string, ): $ReadOnlyArray { return getAllSubNodes(type, typeNode => typeNode.fields).filter( @@ -619,7 +619,7 @@ function getAllFieldNodes( } function getFieldTypeNode( - type: GraphQLObjectType | GraphQLInterfaceType, + type: GraphQLObjectType<*, *> | GraphQLInterfaceType, fieldName: string, ): ?TypeNode { const fieldNode = getFieldNode(type, fieldName); @@ -627,7 +627,7 @@ function getFieldTypeNode( } function getFieldArgNode( - type: GraphQLObjectType | GraphQLInterfaceType, + type: GraphQLObjectType<*, *> | GraphQLInterfaceType, fieldName: string, argName: string, ): ?InputValueDefinitionNode { @@ -635,7 +635,7 @@ function getFieldArgNode( } function getAllFieldArgNodes( - type: GraphQLObjectType | GraphQLInterfaceType, + type: GraphQLObjectType<*, *> | GraphQLInterfaceType, fieldName: string, argName: string, ): $ReadOnlyArray { @@ -652,7 +652,7 @@ function getAllFieldArgNodes( } function getFieldArgTypeNode( - type: GraphQLObjectType | GraphQLInterfaceType, + type: GraphQLObjectType<*, *> | GraphQLInterfaceType, fieldName: string, argName: string, ): ?TypeNode { diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index 531036dca3..ee63062bda 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -161,7 +161,7 @@ export function buildClientSchema( function getObjectType( typeRef: IntrospectionNamedTypeRef, - ): GraphQLObjectType { + ): GraphQLObjectType<*, *> { const type = getType(typeRef); return assertObjectType(type); } @@ -201,7 +201,7 @@ export function buildClientSchema( function buildScalarDef( scalarIntrospection: IntrospectionScalarType, - ): GraphQLScalarType { + ): GraphQLScalarType<*, *> { return new GraphQLScalarType({ name: scalarIntrospection.name, description: scalarIntrospection.description, @@ -211,7 +211,7 @@ export function buildClientSchema( function buildObjectDef( objectIntrospection: IntrospectionObjectType, - ): GraphQLObjectType { + ): GraphQLObjectType<*, *> { if (!objectIntrospection.interfaces) { throw new Error( 'Introspection result missing interfaces: ' + diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index 62b184a5be..016d208e13 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -426,7 +426,7 @@ export function extendSchema( return newValueMap; } - function extendScalarType(type: GraphQLScalarType): GraphQLScalarType { + function extendScalarType(type: GraphQLScalarType<*, *>): GraphQLScalarType<*, *> { const name = type.name; const extensionASTNodes = typeExtensionsMap[name] ? type.extensionASTNodes @@ -444,7 +444,7 @@ export function extendSchema( }); } - function extendObjectType(type: GraphQLObjectType): GraphQLObjectType { + function extendObjectType(type: GraphQLObjectType<*, *>): GraphQLObjectType<*, *> { const name = type.name; const extensionASTNodes = typeExtensionsMap[name] ? type.extensionASTNodes @@ -515,7 +515,7 @@ export function extendSchema( function extendPossibleTypes( type: GraphQLUnionType, - ): Array { + ): Array> { const possibleTypes = type.getTypes().map(extendNamedType); // If there are any extensions to the union, apply those here. @@ -534,7 +534,7 @@ export function extendSchema( } function extendImplementedInterfaces( - type: GraphQLObjectType, + type: GraphQLObjectType<*, *>, ): Array { const interfaces = type.getInterfaces().map(extendNamedType); @@ -554,7 +554,7 @@ export function extendSchema( return interfaces; } - function extendFieldMap(type: GraphQLObjectType | GraphQLInterfaceType) { + function extendFieldMap(type: GraphQLObjectType<*, *> | GraphQLInterfaceType) { const newFieldMap = Object.create(null); const oldFieldMap = type.getFields(); for (const fieldName of Object.keys(oldFieldMap)) { diff --git a/src/utilities/getOperationRootType.js b/src/utilities/getOperationRootType.js index ddc6e99ea1..592bd5b4a0 100644 --- a/src/utilities/getOperationRootType.js +++ b/src/utilities/getOperationRootType.js @@ -21,7 +21,7 @@ import type { GraphQLObjectType } from '../type/definition'; export function getOperationRootType( schema: GraphQLSchema, operation: OperationDefinitionNode | OperationTypeDefinitionNode, -): GraphQLObjectType { +): GraphQLObjectType<*, *> { switch (operation.operation) { case 'query': const queryType = schema.getQueryType(); diff --git a/src/utilities/schemaPrinter.js b/src/utilities/schemaPrinter.js index aa9b01c096..61eb39ddc0 100644 --- a/src/utilities/schemaPrinter.js +++ b/src/utilities/schemaPrinter.js @@ -179,11 +179,11 @@ export function printType(type: GraphQLNamedType, options?: Options): string { throw new Error(`Unknown type: ${(type: empty)}.`); } -function printScalar(type: GraphQLScalarType, options): string { +function printScalar(type: GraphQLScalarType<*, *>, options): string { return printDescription(options, type) + `scalar ${type.name}`; } -function printObject(type: GraphQLObjectType, options): string { +function printObject(type: GraphQLObjectType<*, *>, options): string { const interfaces = type.getInterfaces(); const implementedInterfaces = interfaces.length ? ' implements ' + interfaces.map(i => i.name).join(' & ')