The graphql/utilities
module contains common useful computations to use with
the GraphQL language and type objects. You can import either from the graphql/utilities
module, or from the root graphql
module. For example:
import { introspectionQuery } from 'graphql'; // ES6 var { introspectionQuery } = require('graphql'); // CommonJS
Introspection
Schema Language
function buildSchemaBuilds a Schema object from GraphQL schema language.
function printSchemaPrints the schema in a standard format.
function printIntrospectionSchemaPrints the introspections featurs of the schema in a standard format.
function buildASTSchemaBuilds a schema from a parsed AST Schema.
function typeFromASTLooks up a type referenced in an AST in the GraphQLSchema.
function astFromValueProduces a GraphQL Input Value AST given a JavaScript value.
Visitors
Value Validation
var introspectionQuery: string
A GraphQL query that queries a server's introspection system for enough information to reproduce that server's type system.
function buildClientSchema( introspection: IntrospectionQuery ): GraphQLSchema
Build a GraphQLSchema for use by client tools.
Given the result of a client running the introspection query, creates and returns a GraphQLSchema instance which can be then used with all GraphQL.js tools, but cannot be used to execute a query, as introspection does not represent the "resolver", "parse" or "serialize" functions or any other server-internal mechanisms.
function buildSchema(source: string | Source): GraphQLSchema {
Creates a GraphQLSchema object from GraphQL schema language. The schema will use default resolvers. For more detail on the GraphQL schema language, see the schema language docs or this schema language cheat sheet.
function printSchema(schema: GraphQLSchema): string {
Prints the provided schema in the Schema Language format.
function printIntrospectionSchema(schema: GraphQLSchema): string {
Prints the built-in introspection schema in the Schema Language format.
function buildASTSchema( ast: SchemaDocument, queryTypeName: string, mutationTypeName: ?string ): GraphQLSchema
This takes the ast of a schema document produced by parseSchemaIntoAST
in
graphql/language/schema
and constructs a GraphQLSchema instance which can be
then used with all GraphQL.js tools, but cannot be used to execute a query, as
introspection does not represent the "resolver", "parse" or "serialize"
functions or any other server-internal mechanisms.
function typeFromAST( schema: GraphQLSchema, inputTypeAST: Type ): ?GraphQLType
Given the name of a Type as it appears in a GraphQL AST and a Schema, return the corresponding GraphQLType from that schema.
function astFromValue( value: any, type?: ?GraphQLType ): ?Value
Produces a GraphQL Input Value AST given a JavaScript value.
Optionally, a GraphQL type may be provided, which will be used to disambiguate between value primitives.
class TypeInfo { constructor(schema: GraphQLSchema) getType(): ?GraphQLOutputType { getParentType(): ?GraphQLCompositeType { getInputType(): ?GraphQLInputType { getFieldDef(): ?GraphQLFieldDefinition { getDirective(): ?GraphQLDirective { getArgument(): ?GraphQLArgument { }
TypeInfo is a utility class which, given a GraphQL schema, can keep track
of the current field and type definitions at any point in a GraphQL document
AST during a recursive descent by calling enter(node)
and leave(node)
.
function isValidJSValue(value: any, type: GraphQLInputType): string[]
Given a JavaScript value and a GraphQL type, determine if the value will be accepted for that type. This is primarily useful for validating the runtime values of query variables.
function isValidLiteralValue( type: GraphQLInputType, valueAST: Value ): string[]
Utility for validators which determines if a value literal AST is valid given an input type.
Note that this only validates literal values, variables are assumed to provide values of the correct type.