Skip to content

Commit

Permalink
Merge branch 'APIs-guru-predicates'
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed Dec 4, 2017
2 parents 74d5bf5 + ce937da commit 134184e
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 124 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export {
TypeKind,

// Scalars
specifiedScalarTypes,
GraphQLInt,
GraphQLFloat,
GraphQLString,
Expand All @@ -77,6 +78,7 @@ export {
TypeNameMetaFieldDef,

// GraphQL Types for introspection.
introspectionTypes,
__Schema,
__Directive,
__DirectiveLocation,
Expand All @@ -94,6 +96,9 @@ export {
isCompositeType,
isAbstractType,
isNamedType,
isSpecifiedScalarType,
isIntrospectionType,
isSpecifiedDirective,

// Assertions
assertType,
Expand Down
8 changes: 8 additions & 0 deletions src/type/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ export const specifiedDirectives: Array<GraphQLDirective> = [
GraphQLSkipDirective,
GraphQLDeprecatedDirective,
];

export function isSpecifiedDirective(
directive: GraphQLDirective
): boolean %checks {
return specifiedDirectives.some(
specifiedDirective => specifiedDirective.name === directive.name
);
}
5 changes: 5 additions & 0 deletions src/type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export {
GraphQLDirective,

// Built-in Directives defined by the Spec
isSpecifiedDirective,
specifiedDirectives,
GraphQLIncludeDirective,
GraphQLSkipDirective,
Expand All @@ -60,6 +61,8 @@ export {

// Common built-in scalar instances.
export {
isSpecifiedScalarType,
specifiedScalarTypes,
GraphQLInt,
GraphQLFloat,
GraphQLString,
Expand All @@ -72,6 +75,8 @@ export {
TypeKind,

// GraphQL Types for introspection.
isIntrospectionType,
introspectionTypes,
__Schema,
__Directive,
__DirectiveLocation,
Expand Down
20 changes: 19 additions & 1 deletion src/type/introspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import {
GraphQLList,
GraphQLNonNull,
isAbstractType,
isNamedType,
} from './definition';
import { GraphQLString, GraphQLBoolean } from './scalars';
import { DirectiveLocation } from '../language/directiveLocation';
import type { GraphQLField } from './definition';
import type { GraphQLField, GraphQLNamedType, GraphQLType } from './definition';


export const __Schema = new GraphQLObjectType({
Expand Down Expand Up @@ -451,3 +452,20 @@ export const TypeNameMetaFieldDef: GraphQLField<*, *> = {
args: [],
resolve: (source, args, context, { parentType }) => parentType.name
};

export const introspectionTypes: Array<GraphQLNamedType> = [
__Schema,
__Directive,
__DirectiveLocation,
__Type,
__Field,
__InputValue,
__EnumValue,
__TypeKind,
];

export function isIntrospectionType(type: ?GraphQLType): boolean %checks {
return isNamedType(type) && introspectionTypes.some(
introspectionType => introspectionType.name === type.name
);
}
17 changes: 16 additions & 1 deletion src/type/scalars.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
* @flow
*/

import { GraphQLScalarType } from './definition';
import { GraphQLScalarType, isNamedType } from './definition';
import * as Kind from '../language/kinds';
import type { GraphQLType } from './definition';

// As per the GraphQL Spec, Integers are only treated as valid when a valid
// 32-bit signed integer, providing the broadest support across platforms.
Expand Down Expand Up @@ -135,3 +136,17 @@ export const GraphQLID = new GraphQLScalarType({
undefined;
}
});

export const specifiedScalarTypes: Array<GraphQLScalarType> = [
GraphQLString,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean,
GraphQLID,
];

export function isSpecifiedScalarType(type: ?GraphQLType): boolean %checks {
return isNamedType(type) && specifiedScalarTypes.some(
specifiedScalarType => specifiedScalarType.name === type.name
);
}
67 changes: 21 additions & 46 deletions src/utilities/buildASTSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import invariant from '../jsutils/invariant';
import keyMap from '../jsutils/keyMap';
import keyValMap from '../jsutils/keyValMap';
import type {ObjMap} from '../jsutils/ObjMap';
import { valueFromAST } from './valueFromAST';
Expand Down Expand Up @@ -39,15 +40,9 @@ import type {
DirectiveDefinitionNode,
} from '../language/ast';

import { GraphQLSchema } from '../type/schema';

import {
GraphQLString,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean,
GraphQLID,
} from '../type/scalars';
import type {
DirectiveLocationEnum
} from '../language/directiveLocation';

import {
GraphQLScalarType,
Expand All @@ -62,35 +57,26 @@ import {
assertOutputType,
} from '../type/definition';

import type {
GraphQLType,
GraphQLNamedType,
GraphQLInputType,
GraphQLOutputType,
GraphQLFieldConfig,
} from '../type/definition';

import {
GraphQLDirective,
GraphQLSkipDirective,
GraphQLIncludeDirective,
GraphQLDeprecatedDirective,
} from '../type/directives';

import type {
DirectiveLocationEnum
} from '../language/directiveLocation';
import { introspectionTypes } from '../type/introspection';

import {
__Schema,
__Directive,
__DirectiveLocation,
__Type,
__Field,
__InputValue,
__EnumValue,
__TypeKind,
} from '../type/introspection';
import { specifiedScalarTypes } from '../type/scalars';

import { GraphQLSchema } from '../type/schema';

import type {
GraphQLType,
GraphQLNamedType,
GraphQLInputType,
GraphQLOutputType,
GraphQLFieldConfig,
} from '../type/definition';

type Options = {| commentDescriptions?: boolean |};

Expand Down Expand Up @@ -260,7 +246,7 @@ export class ASTDefinitionBuilder {
_typeDefinitionsMap: TypeDefinitionsMap;
_options: ?Options;
_resolveType: TypeResolver;
_cache: { [typeName: string]: GraphQLNamedType };
_cache: ObjMap<GraphQLNamedType>;

constructor(
typeDefinitionsMap: TypeDefinitionsMap,
Expand All @@ -271,21 +257,10 @@ export class ASTDefinitionBuilder {
this._options = options;
this._resolveType = resolveType;
// Initialize to the GraphQL built in scalars and introspection types.
this._cache = {
String: GraphQLString,
Int: GraphQLInt,
Float: GraphQLFloat,
Boolean: GraphQLBoolean,
ID: GraphQLID,
__Schema,
__Directive,
__DirectiveLocation,
__Type,
__Field,
__InputValue,
__EnumValue,
__TypeKind,
};
this._cache = keyMap(
specifiedScalarTypes.concat(introspectionTypes),
type => type.name
);
}

_buildType(typeName: string, typeNode?: ?NamedTypeNode): GraphQLNamedType {
Expand Down
53 changes: 12 additions & 41 deletions src/utilities/buildClientSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { valueFromAST } from './valueFromAST';
import { parseValue } from '../language/parser';
import { GraphQLSchema } from '../type/schema';

import { DirectiveLocation } from '../language/directiveLocation';

import {
isInputType,
isOutputType,
Expand All @@ -27,38 +29,19 @@ import {
GraphQLNonNull,
} from '../type/definition';

import {
__Schema,
__Directive,
__DirectiveLocation,
__Type,
__Field,
__InputValue,
__EnumValue,
__TypeKind,
} from '../type/introspection';

import {
GraphQLInt,
GraphQLFloat,
GraphQLString,
GraphQLBoolean,
GraphQLID
} from '../type/scalars';

import { GraphQLDirective } from '../type/directives';

import { DirectiveLocation } from '../language/directiveLocation';

import { TypeKind } from '../type/introspection';

import type {
GraphQLType,
GraphQLInputType,
GraphQLOutputType,
GraphQLNamedType,
} from '../type/definition';

import { GraphQLDirective } from '../type/directives';

import { introspectionTypes, TypeKind } from '../type/introspection';

import { specifiedScalarTypes } from '../type/scalars';

import type {
IntrospectionQuery,
IntrospectionType,
Expand All @@ -74,7 +57,6 @@ import type {
IntrospectionNamedTypeRef,
} from './introspectionQuery';


/**
* Build a GraphQLSchema for use by client tools.
*
Expand Down Expand Up @@ -103,21 +85,10 @@ export function buildClientSchema(
// A cache to use to store the actual GraphQLType definition objects by name.
// Initialize to the GraphQL built in scalars. All functions below are inline
// so that this type def cache is within the scope of the closure.
const typeDefCache = {
String: GraphQLString,
Int: GraphQLInt,
Float: GraphQLFloat,
Boolean: GraphQLBoolean,
ID: GraphQLID,
__Schema,
__Directive,
__DirectiveLocation,
__Type,
__Field,
__InputValue,
__EnumValue,
__TypeKind,
};
const typeDefCache = keyMap(
specifiedScalarTypes.concat(introspectionTypes),
type => type.name
);

// Given a type reference in introspection, return the GraphQLType instance.
// preferring cached instances before building new instances.
Expand Down
Loading

0 comments on commit 134184e

Please sign in to comment.