From ad261d041d385a0c64854ff7027715bd50fcd75b Mon Sep 17 00:00:00 2001 From: Caleb Meredith Date: Fri, 28 Oct 2016 12:01:37 -0400 Subject: [PATCH] Expose structural GraphQL types (#12142) * Expose structural GraphQL types https://github.com/DefinitelyTyped/DefinitelyTyped/pull/12078, but on the `master` branch. /cc @TonyPythoneer, @zhengbli * Update graphql.d.ts --- graphql/graphql.d.ts | 178 ++++++++++++------------------------------- 1 file changed, 47 insertions(+), 131 deletions(-) diff --git a/graphql/graphql.d.ts b/graphql/graphql.d.ts index 570fbe3a2f..c7310ab3cc 100644 --- a/graphql/graphql.d.ts +++ b/graphql/graphql.d.ts @@ -19,69 +19,7 @@ declare module "graphql" { // Create and operate on GraphQL type definitions and schema. - export { - GraphQLSchema, - - // Definitions - GraphQLScalarType, - GraphQLObjectType, - GraphQLInterfaceType, - GraphQLUnionType, - GraphQLEnumType, - GraphQLInputObjectType, - GraphQLList, - GraphQLNonNull, - GraphQLDirective, - - // "Enum" of Type Kinds - TypeKind, - - // "Enum" of Directive Locations - DirectiveLocation, - - // Scalars - GraphQLInt, - GraphQLFloat, - GraphQLString, - GraphQLBoolean, - GraphQLID, - - // Built-in Directives defined by the Spec - specifiedDirectives, - GraphQLIncludeDirective, - GraphQLSkipDirective, - GraphQLDeprecatedDirective, - - // Constant Deprecation Reason - DEFAULT_DEPRECATION_REASON, - - // Meta-field definitions. - SchemaMetaFieldDef, - TypeMetaFieldDef, - TypeNameMetaFieldDef, - - // GraphQL Types for introspection. - __Schema, - __Directive, - __DirectiveLocation, - __Type, - __Field, - __InputValue, - __EnumValue, - __TypeKind, - - // Predicates - isType, - isInputType, - isOutputType, - isLeafType, - isCompositeType, - isAbstractType, - - // Un-modifiers - getNullableType, - getNamedType, - } from 'graphql/type'; + export * from 'graphql/type'; // Parse and operate on GraphQL language source files. @@ -994,29 +932,7 @@ declare module "graphql/type/index" { // GraphQL Schema definition export { GraphQLSchema } from 'graphql/type/schema'; - export { - // Predicates - isType, - isInputType, - isOutputType, - isLeafType, - isCompositeType, - isAbstractType, - - // Un-modifiers - getNullableType, - getNamedType, - - // Definitions - GraphQLScalarType, - GraphQLObjectType, - GraphQLInterfaceType, - GraphQLUnionType, - GraphQLEnumType, - GraphQLInputObjectType, - GraphQLList, - GraphQLNonNull, - } from 'graphql/type/definition'; + export * from 'graphql/type/definition'; export { // "Enum" of Directive Locations @@ -1078,7 +994,7 @@ declare module "graphql/type/definition" { /** * These are all of the possible kinds of types. */ - type GraphQLType = + export type GraphQLType = GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | @@ -1088,12 +1004,12 @@ declare module "graphql/type/definition" { GraphQLList | GraphQLNonNull; - function isType(type: any): boolean; + export function isType(type: any): type is GraphQLType; /** * These types may be used as input types for arguments and directives. */ - type GraphQLInputType = + export type GraphQLInputType = GraphQLScalarType | GraphQLEnumType | GraphQLInputObjectType | @@ -1105,12 +1021,12 @@ declare module "graphql/type/definition" { GraphQLList >; - function isInputType(type: GraphQLType): boolean; + export function isInputType(type: GraphQLType): type is GraphQLInputType; /** * These types may be used as output types as the result of fields. */ - type GraphQLOutputType = + export type GraphQLOutputType = GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | @@ -1126,40 +1042,40 @@ declare module "graphql/type/definition" { GraphQLList >; - function isOutputType(type: GraphQLType): boolean; + export function isOutputType(type: GraphQLType): type is GraphQLOutputType; /** * These types may describe types which may be leaf values. */ - type GraphQLLeafType = + export type GraphQLLeafType = GraphQLScalarType | GraphQLEnumType; - function isLeafType(type: GraphQLType): boolean; + export function isLeafType(type: GraphQLType): type is GraphQLLeafType; /** * These types may describe the parent context of a selection set. */ - type GraphQLCompositeType = + export type GraphQLCompositeType = GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType; - function isCompositeType(type: GraphQLType): boolean; + export function isCompositeType(type: GraphQLType): type is GraphQLCompositeType; /** * These types may describe the parent context of a selection set. */ - type GraphQLAbstractType = + export type GraphQLAbstractType = GraphQLInterfaceType | GraphQLUnionType; - function isAbstractType(type: GraphQLType): boolean; + export function isAbstractType(type: GraphQLType): type is GraphQLAbstractType; /** * These types can all accept null as a value. */ - type GraphQLNullableType = + export type GraphQLNullableType = GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | @@ -1168,14 +1084,14 @@ declare module "graphql/type/definition" { GraphQLInputObjectType | GraphQLList; - function getNullableType( + export function getNullableType( type: T ): (T & GraphQLNullableType); /** * These named types do not include modifiers like List or NonNull. */ - type GraphQLNamedType = + export type GraphQLNamedType = GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | @@ -1183,7 +1099,7 @@ declare module "graphql/type/definition" { GraphQLEnumType | GraphQLInputObjectType; - function getNamedType(type: GraphQLType): GraphQLNamedType + export function getNamedType(type: GraphQLType): GraphQLNamedType /** * Used while defining GraphQL types to allow for circular references in @@ -1225,7 +1141,7 @@ declare module "graphql/type/definition" { toString(): string; } - interface GraphQLScalarTypeConfig { + export interface GraphQLScalarTypeConfig { name: string; description?: string; serialize: (value: any) => TInternal; @@ -1283,7 +1199,7 @@ declare module "graphql/type/definition" { // - interface GraphQLObjectTypeConfig { + export interface GraphQLObjectTypeConfig { name: string; interfaces?: Thunk>; fields: Thunk>; @@ -1291,26 +1207,26 @@ declare module "graphql/type/definition" { description?: string } - type GraphQLTypeResolveFn = ( + export type GraphQLTypeResolveFn = ( value: any, context: any, info: GraphQLResolveInfo ) => GraphQLObjectType; - type GraphQLIsTypeOfFn = ( + export type GraphQLIsTypeOfFn = ( source: any, context: any, info: GraphQLResolveInfo ) => boolean; - type GraphQLFieldResolveFn = ( + export type GraphQLFieldResolveFn = ( source: TSource, args: { [argName: string]: any }, context: any, info: GraphQLResolveInfo ) => any; - interface GraphQLResolveInfo { + export interface GraphQLResolveInfo { fieldName: string; fieldASTs: Array; returnType: GraphQLOutputType; @@ -1323,7 +1239,7 @@ declare module "graphql/type/definition" { variableValues: { [variableName: string]: any }; } - interface GraphQLFieldConfig { + export interface GraphQLFieldConfig { type: GraphQLOutputType; args?: GraphQLFieldConfigArgumentMap; resolve?: GraphQLFieldResolveFn; @@ -1331,21 +1247,21 @@ declare module "graphql/type/definition" { description?: string; } - interface GraphQLFieldConfigArgumentMap { + export interface GraphQLFieldConfigArgumentMap { [argName: string]: GraphQLArgumentConfig; } - interface GraphQLArgumentConfig { + export interface GraphQLArgumentConfig { type: GraphQLInputType; defaultValue?: any; description?: string; } - interface GraphQLFieldConfigMap { + export interface GraphQLFieldConfigMap { [fieldName: string]: GraphQLFieldConfig; } - interface GraphQLFieldDefinition { + export interface GraphQLFieldDefinition { name: string; description: string; type: GraphQLOutputType; @@ -1355,14 +1271,14 @@ declare module "graphql/type/definition" { deprecationReason: string; } - interface GraphQLArgument { + export interface GraphQLArgument { name: string; type: GraphQLInputType; defaultValue?: any; description?: string; } - interface GraphQLFieldDefinitionMap { + export interface GraphQLFieldDefinitionMap { [fieldName: string]: GraphQLFieldDefinition; } @@ -1396,7 +1312,7 @@ declare module "graphql/type/definition" { toString(): string; } - interface GraphQLInterfaceTypeConfig { + export interface GraphQLInterfaceTypeConfig { name: string, fields: Thunk>, /** @@ -1443,7 +1359,7 @@ declare module "graphql/type/definition" { toString(): string; } - interface GraphQLUnionTypeConfig { + export interface GraphQLUnionTypeConfig { name: string, types: Thunk>, /** @@ -1488,23 +1404,23 @@ declare module "graphql/type/definition" { toString(): string; } - interface GraphQLEnumTypeConfig { + export interface GraphQLEnumTypeConfig { name: string; values: GraphQLEnumValueConfigMap; description?: string; } - interface GraphQLEnumValueConfigMap { + export interface GraphQLEnumValueConfigMap { [valueName: string]: GraphQLEnumValueConfig; } - interface GraphQLEnumValueConfig { + export interface GraphQLEnumValueConfig { value?: any; deprecationReason?: string; description?: string; } - interface GraphQLEnumValueDefinition { + export interface GraphQLEnumValueDefinition { name: string; description: string; deprecationReason: string; @@ -1534,36 +1450,36 @@ declare module "graphql/type/definition" { class GraphQLInputObjectType { name: string; description: string; - constructor(config: InputObjectConfig); - getFields(): InputObjectFieldMap; + constructor(config: GraphQLInputObjectTypeConfig); + getFields(): GraphQLInputFieldDefinitionMap; toString(): string; } - interface InputObjectConfig { + export interface GraphQLInputObjectTypeConfig { name: string; - fields: Thunk; + fields: Thunk; description?: string; } - interface InputObjectFieldConfig { + export interface GraphQLInputFieldConfig { type: GraphQLInputType; defaultValue?: any; description?: string; } - interface InputObjectConfigFieldMap { - [fieldName: string]: InputObjectFieldConfig; + export interface GraphQLInputFieldConfigMap { + [fieldName: string]: GraphQLInputFieldConfig; } - interface InputObjectField { + export interface GraphQLInputFieldDefinition { name: string; type: GraphQLInputType; defaultValue?: any; description?: string; } - interface InputObjectFieldMap { - [fieldName: string]: InputObjectField; + export interface GraphQLInputFieldDefinitionMap { + [fieldName: string]: GraphQLInputFieldDefinition; } /**