From aefa03380269e82734a652e422ce55a6dfc8706d Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Thu, 30 Jul 2015 18:00:19 -0700 Subject: [PATCH] export a bunch of definition types and predicates --- src/type/definition.js | 36 +++++++++++++++---------------- src/type/index.js | 49 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/src/type/definition.js b/src/type/definition.js index ad91c7715e..df3cdfddd0 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -200,7 +200,7 @@ export class GraphQLScalarType/**/ { } } -type GraphQLScalarTypeConfig/**/ = { +export type GraphQLScalarTypeConfig/**/ = { name: string; description?: ?string; coerce: (value: any) => ?any/*T*/; @@ -332,7 +332,7 @@ function addImplementationToInterfaces(impl) { }); } -type GraphQLObjectTypeConfig = { +export type GraphQLObjectTypeConfig = { name: string; interfaces?: GraphQLInterfacesThunk | Array; fields: GraphQLFieldConfigMapThunk | GraphQLFieldConfigMap; @@ -344,7 +344,7 @@ type GraphQLInterfacesThunk = () => Array; type GraphQLFieldConfigMapThunk = () => GraphQLFieldConfigMap; -type GraphQLFieldConfig = { +export type GraphQLFieldConfig = { type: GraphQLOutputType; args?: GraphQLFieldConfigArgumentMap; resolve?: ( @@ -360,16 +360,16 @@ type GraphQLFieldConfig = { description?: ?string; } -type GraphQLFieldConfigArgumentMap = { +export type GraphQLFieldConfigArgumentMap = { [argName: string]: GraphQLArgumentConfig; }; -type GraphQLArgumentConfig = { +export type GraphQLArgumentConfig = { type: GraphQLInputType; defaultValue?: any; } -type GraphQLFieldConfigMap = { +export type GraphQLFieldConfigMap = { [fieldName: string]: GraphQLFieldConfig; }; @@ -397,7 +397,7 @@ export type GraphQLArgument = { description?: ?string; }; -type GraphQLFieldDefinitionMap = { +export type GraphQLFieldDefinitionMap = { [fieldName: string]: GraphQLFieldDefinition; }; @@ -492,7 +492,7 @@ function getTypeOf( } } -type GraphQLInterfaceTypeConfig = { +export type GraphQLInterfaceTypeConfig = { name: string, fields: GraphQLFieldConfigMapThunk | GraphQLFieldConfigMap, /** @@ -584,7 +584,7 @@ export class GraphQLUnionType { } } -type GraphQLUnionTypeConfig = { +export type GraphQLUnionTypeConfig = { name: string, types: Array, /** @@ -695,27 +695,27 @@ export class GraphQLEnumType/**/ { } } -type GraphQLEnumTypeConfig/**/ = { +export type GraphQLEnumTypeConfig/**/ = { name: string; values: GraphQLEnumValueConfigMap/**/; description?: ?string; } -type GraphQLEnumValueConfigMap/**/ = { +export type GraphQLEnumValueConfigMap/**/ = { [valueName: string]: GraphQLEnumValueConfig/**/; }; -type GraphQLEnumValueConfig/**/ = { +export type GraphQLEnumValueConfig/**/ = { value?: any/*T*/; deprecationReason?: string; description?: ?string; } -type GraphQLEnumValueDefinitionMap/**/ = { +export type GraphQLEnumValueDefinitionMap/**/ = { [valueName: string]: GraphQLEnumValueDefinition/**/; }; -type GraphQLEnumValueDefinition/**/ = { +export type GraphQLEnumValueDefinition/**/ = { name: string; value?: any/*T*/; deprecationReason?: string; @@ -777,7 +777,7 @@ export class GraphQLInputObjectType { } } -type InputObjectConfig = { +export type InputObjectConfig = { name: string; fields: InputObjectConfigFieldMapThunk | InputObjectConfigFieldMap; description?: ?string; @@ -785,13 +785,13 @@ type InputObjectConfig = { type InputObjectConfigFieldMapThunk = () => InputObjectConfigFieldMap; -type InputObjectFieldConfig = { +export type InputObjectFieldConfig = { type: GraphQLInputType; defaultValue?: any; description?: ?string; } -type InputObjectConfigFieldMap = { +export type InputObjectConfigFieldMap = { [fieldName: string]: InputObjectFieldConfig; }; @@ -802,7 +802,7 @@ export type InputObjectField = { description?: ?string; } -type InputObjectFieldMap = { +export type InputObjectFieldMap = { [fieldName: string]: InputObjectField; }; diff --git a/src/type/index.js b/src/type/index.js index ad542e1719..b694432e4d 100644 --- a/src/type/index.js +++ b/src/type/index.js @@ -1,3 +1,4 @@ +/*@flow*/ /** * Copyright (c) 2015, Facebook, Inc. * All rights reserved. @@ -7,11 +8,22 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -export { - GraphQLSchema -} from './schema'; +// GraphQL Schema definition +export { GraphQLSchema } from './schema'; export { + // Predicates + isInputType, + isOutputType, + isLeafType, + isCompositeType, + isAbstractType, + + // Un-modifiers + getNullableType, + getNamedType, + + // Definitions GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, @@ -19,13 +31,40 @@ export { GraphQLEnumType, GraphQLInputObjectType, GraphQLList, - GraphQLNonNull + GraphQLNonNull, } from './definition'; +// Common built-in scalar instances. export { GraphQLInt, GraphQLFloat, GraphQLString, GraphQLBoolean, - GraphQLID + GraphQLID, } from './scalars'; + +// Export flow types. + +// Note: a future version of flow may support `export type {} from ''`, but +// until then, this is a viable workaround. + +// These are unions of the various GraphQL type definitions that are useful +// annotation alongside the GraphQL type predicates. +import type { + GraphQLType, + GraphQLInputType, + GraphQLOutputType, + GraphQLLeafType, + GraphQLCompositeType, + GraphQLAbstractType, + GraphQLNullableType, + GraphQLNamedType, +} from './definition'; +export type GraphQLType = GraphQLType; +export type GraphQLInputType = GraphQLInputType; +export type GraphQLOutputType = GraphQLOutputType; +export type GraphQLLeafType = GraphQLLeafType; +export type GraphQLCompositeType = GraphQLCompositeType; +export type GraphQLAbstractType = GraphQLAbstractType; +export type GraphQLNullableType = GraphQLNullableType; +export type GraphQLNamedType = GraphQLNamedType;