diff --git a/src/index.js b/src/index.js index 742af0f795..26d86086c4 100644 --- a/src/index.js +++ b/src/index.js @@ -379,12 +379,16 @@ export type { IntrospectionEnumValue, IntrospectionField, IntrospectionInputObjectType, + IntrospectionInputType, + IntrospectionInputTypeRef, IntrospectionInputValue, IntrospectionInterfaceType, IntrospectionListTypeRef, IntrospectionNamedTypeRef, IntrospectionNonNullTypeRef, IntrospectionObjectType, + IntrospectionOutputType, + IntrospectionOutputTypeRef, IntrospectionQuery, IntrospectionScalarType, IntrospectionSchema, diff --git a/src/jsutils/keyMap.js b/src/jsutils/keyMap.js index e07da542c7..5b2dbfaf17 100644 --- a/src/jsutils/keyMap.js +++ b/src/jsutils/keyMap.js @@ -33,7 +33,7 @@ import type {ObjMap} from './ObjMap'; * */ export default function keyMap( - list: Array, + list: $ReadOnlyArray, keyFn: (item: T) => string ): ObjMap { return list.reduce( diff --git a/src/jsutils/keyValMap.js b/src/jsutils/keyValMap.js index 4f6591f478..d002f2d08d 100644 --- a/src/jsutils/keyValMap.js +++ b/src/jsutils/keyValMap.js @@ -27,7 +27,7 @@ import type {ObjMap} from './ObjMap'; * */ export default function keyValMap( - list: Array, + list: $ReadOnlyArray, keyFn: (item: T) => string, valFn: (item: T) => V ): ObjMap { diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index 1bbf90a1d4..443e64629b 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -67,8 +67,9 @@ import type { IntrospectionEnumType, IntrospectionInputObjectType, IntrospectionTypeRef, - IntrospectionListTypeRef, - IntrospectionNonNullTypeRef, + IntrospectionInputTypeRef, + IntrospectionOutputTypeRef, + IntrospectionNamedTypeRef, } from './introspectionQuery'; @@ -120,14 +121,14 @@ export function buildClientSchema( // preferring cached instances before building new instances. function getType(typeRef: IntrospectionTypeRef): GraphQLType { if (typeRef.kind === TypeKind.LIST) { - const itemRef = ((typeRef: any): IntrospectionListTypeRef).ofType; + const itemRef = typeRef.ofType; if (!itemRef) { throw new Error('Decorated type deeper than introspection query.'); } return new GraphQLList(getType(itemRef)); } if (typeRef.kind === TypeKind.NON_NULL) { - const nullableRef = ((typeRef: any): IntrospectionNonNullTypeRef).ofType; + const nullableRef = typeRef.ofType; if (!nullableRef) { throw new Error('Decorated type deeper than introspection query.'); } @@ -161,7 +162,7 @@ export function buildClientSchema( return typeDef; } - function getInputType(typeRef: IntrospectionTypeRef): GraphQLInputType { + function getInputType(typeRef: IntrospectionInputTypeRef): GraphQLInputType { const type = getType(typeRef); invariant( isInputType(type), @@ -170,7 +171,9 @@ export function buildClientSchema( return type; } - function getOutputType(typeRef: IntrospectionTypeRef): GraphQLOutputType { + function getOutputType( + typeRef: IntrospectionOutputTypeRef + ): GraphQLOutputType { const type = getType(typeRef); invariant( isOutputType(type), @@ -179,7 +182,9 @@ export function buildClientSchema( return type; } - function getObjectType(typeRef: IntrospectionTypeRef): GraphQLObjectType { + function getObjectType( + typeRef: IntrospectionNamedTypeRef + ): GraphQLObjectType { const type = getType(typeRef); invariant( type instanceof GraphQLObjectType, diff --git a/src/utilities/index.js b/src/utilities/index.js index 268697f37f..ce8c87cf42 100644 --- a/src/utilities/index.js +++ b/src/utilities/index.js @@ -13,6 +13,8 @@ export type { IntrospectionQuery, IntrospectionSchema, IntrospectionType, + IntrospectionInputType, + IntrospectionOutputType, IntrospectionScalarType, IntrospectionObjectType, IntrospectionInterfaceType, @@ -20,6 +22,8 @@ export type { IntrospectionEnumType, IntrospectionInputObjectType, IntrospectionTypeRef, + IntrospectionInputTypeRef, + IntrospectionOutputTypeRef, IntrospectionNamedTypeRef, IntrospectionListTypeRef, IntrospectionNonNullTypeRef, diff --git a/src/utilities/introspectionQuery.js b/src/utilities/introspectionQuery.js index bc1422acb5..df84cc832d 100644 --- a/src/utilities/introspectionQuery.js +++ b/src/utilities/introspectionQuery.js @@ -104,17 +104,17 @@ export const introspectionQuery = ` } `; -export type IntrospectionQuery = { - __schema: IntrospectionSchema -}; - -export type IntrospectionSchema = { - queryType: IntrospectionNamedTypeRef; - mutationType: ?IntrospectionNamedTypeRef; - subscriptionType: ?IntrospectionNamedTypeRef; - types: Array; - directives: Array; -}; +export type IntrospectionQuery = {| + +__schema: IntrospectionSchema; +|}; + +export type IntrospectionSchema = {| + +queryType: IntrospectionNamedTypeRef; + +mutationType: ?IntrospectionNamedTypeRef; + +subscriptionType: ?IntrospectionNamedTypeRef; + +types: $ReadOnlyArray; + +directives: $ReadOnlyArray; +|}; export type IntrospectionType = | IntrospectionScalarType @@ -124,95 +124,138 @@ export type IntrospectionType = | IntrospectionEnumType | IntrospectionInputObjectType; -export type IntrospectionScalarType = { - kind: 'SCALAR'; - name: string; - description: ?string; -}; - -export type IntrospectionObjectType = { - kind: 'OBJECT'; - name: string; - description: ?string; - fields: Array; - interfaces: Array; -}; - -export type IntrospectionInterfaceType = { - kind: 'INTERFACE'; - name: string; - description: ?string; - fields: Array; - possibleTypes: Array; -}; - -export type IntrospectionUnionType = { - kind: 'UNION'; - name: string; - description: ?string; - possibleTypes: Array; -}; - -export type IntrospectionEnumType = { - kind: 'ENUM'; - name: string; - description: ?string; - enumValues: Array; -}; - -export type IntrospectionInputObjectType = { - kind: 'INPUT_OBJECT'; - name: string; - description: ?string; - inputFields: Array; -}; +export type IntrospectionOutputType = + | IntrospectionScalarType + | IntrospectionObjectType + | IntrospectionInterfaceType + | IntrospectionUnionType + | IntrospectionEnumType; + +export type IntrospectionInputType = + | IntrospectionScalarType + | IntrospectionEnumType + | IntrospectionInputObjectType; + +export type IntrospectionScalarType = {| + +kind: 'SCALAR'; + +name: string; + +description: ?string; +|}; + +export type IntrospectionObjectType = {| + +kind: 'OBJECT'; + +name: string; + +description: ?string; + +fields: $ReadOnlyArray; + +interfaces: $ReadOnlyArray< + IntrospectionNamedTypeRef + >; +|}; + +export type IntrospectionInterfaceType = {| + +kind: 'INTERFACE'; + +name: string; + +description: ?string; + +fields: $ReadOnlyArray; + +possibleTypes: $ReadOnlyArray< + IntrospectionNamedTypeRef + >; +|}; + +export type IntrospectionUnionType = {| + +kind: 'UNION'; + +name: string; + +description: ?string; + +possibleTypes: $ReadOnlyArray< + IntrospectionNamedTypeRef + >; +|}; + +export type IntrospectionEnumType = {| + +kind: 'ENUM'; + +name: string; + +description: ?string; + +enumValues: $ReadOnlyArray; +|}; + +export type IntrospectionInputObjectType = {| + +kind: 'INPUT_OBJECT'; + +name: string; + +description: ?string; + +inputFields: $ReadOnlyArray; +|}; + +export type IntrospectionListTypeRef< + T: IntrospectionTypeRef = IntrospectionTypeRef +> = {| + +kind: 'LIST'; + +ofType?: T; +|}; + +export type IntrospectionNonNullTypeRef< + T: IntrospectionTypeRef = IntrospectionTypeRef +> = {| + +kind: 'NON_NULL'; + +ofType?: T; +|}; export type IntrospectionTypeRef = - | IntrospectionNamedTypeRef - | IntrospectionListTypeRef - | IntrospectionNonNullTypeRef; - -export type IntrospectionNamedTypeRef = { - kind: string; - name: string; -}; - -export type IntrospectionListTypeRef = { - kind: 'LIST'; - ofType?: IntrospectionTypeRef; -}; - -export type IntrospectionNonNullTypeRef = { - kind: 'NON_NULL'; - ofType?: IntrospectionTypeRef; -}; - -export type IntrospectionField = { - name: string; - description: ?string; - args: Array; - type: IntrospectionTypeRef; - isDeprecated: boolean; - deprecationReason: ?string; -}; - -export type IntrospectionInputValue = { - name: string; - description: ?string; - type: IntrospectionTypeRef; - defaultValue: ?string; -}; - -export type IntrospectionEnumValue = { - name: string; - description: ?string; - isDeprecated: boolean; - deprecationReason: ?string; -}; - -export type IntrospectionDirective = { - name: string; - description: ?string; - locations: Array; - args: Array; -}; + | IntrospectionNamedTypeRef + | IntrospectionListTypeRef + | IntrospectionNonNullTypeRef< + | IntrospectionNamedTypeRef + | IntrospectionListTypeRef + >; + +export type IntrospectionOutputTypeRef = + | IntrospectionNamedTypeRef + | IntrospectionListTypeRef + | IntrospectionNonNullTypeRef< + | IntrospectionNamedTypeRef + | IntrospectionListTypeRef + >; + +export type IntrospectionInputTypeRef = + | IntrospectionNamedTypeRef + | IntrospectionListTypeRef + | IntrospectionNonNullTypeRef< + | IntrospectionNamedTypeRef + | IntrospectionListTypeRef + >; + +export type IntrospectionNamedTypeRef< + T: IntrospectionType = IntrospectionType +> = {| + +kind: $PropertyType; + +name: string; +|}; + +export type IntrospectionField = {| + +name: string; + +description: ?string; + +args: $ReadOnlyArray; + +type: IntrospectionOutputTypeRef; + +isDeprecated: boolean; + +deprecationReason: ?string; +|}; + +export type IntrospectionInputValue = {| + +name: string; + +description: ?string; + +type: IntrospectionInputTypeRef; + +defaultValue: ?string; +|}; + +export type IntrospectionEnumValue = {| + +name: string; + +description: ?string; + +isDeprecated: boolean; + +deprecationReason: ?string; +|}; + +export type IntrospectionDirective = {| + +name: string; + +description: ?string; + +locations: $ReadOnlyArray; + +args: $ReadOnlyArray; +|};