UNPKG

graphql

Version:

A Query Language and Runtime which can target any service.

334 lines (314 loc) 11.3 kB
/* @flow weak */ /** * Copyright (c) 2015, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ 'use strict'; var _Object$defineProperty = require('babel-runtime/core-js/object/define-property')['default']; var _Object$keys = require('babel-runtime/core-js/object/keys')['default']; _Object$defineProperty(exports, '__esModule', { value: true }); var _definition = require('./definition'); var _scalars = require('./scalars'); var __Schema = new _definition.GraphQLObjectType({ name: '__Schema', description: 'A GraphQL Schema defines the capabilities of a GraphQL ' + 'server. It exposes all available types and directives on ' + 'the server, as well as the entry points for query and ' + 'mutation operations.', fields: function fields() { return { types: { description: 'A list of all types supported by this server.', type: new _definition.GraphQLNonNull(new _definition.GraphQLList(new _definition.GraphQLNonNull(__Type))), resolve: function resolve(schema) { var typeMap = schema.getTypeMap(); return _Object$keys(typeMap).map(function (key) { return typeMap[key]; }); } }, queryType: { description: 'The type that query operations will be rooted at.', type: new _definition.GraphQLNonNull(__Type), resolve: function resolve(schema) { return schema.getQueryType(); } }, mutationType: { description: 'If this server supports mutation, the type that ' + 'mutation operations will be rooted at.', type: __Type, resolve: function resolve(schema) { return schema.getMutationType(); } }, directives: { description: 'A list of all directives supported by this server.', type: new _definition.GraphQLNonNull(new _definition.GraphQLList(new _definition.GraphQLNonNull(__Directive))), resolve: function resolve(schema) { return schema.getDirectives(); } } }; } }); exports.__Schema = __Schema; var __Directive = new _definition.GraphQLObjectType({ name: '__Directive', fields: function fields() { return { name: { type: _scalars.GraphQLString }, description: { type: _scalars.GraphQLString }, type: { type: __Type }, onOperation: { type: _scalars.GraphQLBoolean }, onFragment: { type: _scalars.GraphQLBoolean }, onField: { type: _scalars.GraphQLBoolean } }; } }); var __Type = new _definition.GraphQLObjectType({ name: '__Type', fields: function fields() { return { kind: { type: new _definition.GraphQLNonNull(__TypeKind), resolve: function resolve(type) { if (type instanceof _definition.GraphQLScalarType) { return TypeKind.SCALAR; } else if (type instanceof _definition.GraphQLObjectType) { return TypeKind.OBJECT; } else if (type instanceof _definition.GraphQLInterfaceType) { return TypeKind.INTERFACE; } else if (type instanceof _definition.GraphQLUnionType) { return TypeKind.UNION; } else if (type instanceof _definition.GraphQLEnumType) { return TypeKind.ENUM; } else if (type instanceof _definition.GraphQLInputObjectType) { return TypeKind.INPUT_OBJECT; } else if (type instanceof _definition.GraphQLList) { return TypeKind.LIST; } else if (type instanceof _definition.GraphQLNonNull) { return TypeKind.NON_NULL; } else { throw new Error('Unknown kind of type: ' + type); } } }, name: { type: _scalars.GraphQLString }, description: { type: _scalars.GraphQLString }, fields: { type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__Field)), args: { includeDeprecated: { type: _scalars.GraphQLBoolean, defaultValue: false } }, resolve: function resolve(type, _ref) { var includeDeprecated = _ref.includeDeprecated; if (type instanceof _definition.GraphQLObjectType || type instanceof _definition.GraphQLInterfaceType) { var fieldMap = type.getFields(); var fields = _Object$keys(fieldMap).map(function (fieldName) { return fieldMap[fieldName]; }); if (!includeDeprecated) { fields = fields.filter(function (field) { return !field.deprecationReason; }); } return fields; } return null; } }, interfaces: { type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__Type)), resolve: function resolve(type) { if (type instanceof _definition.GraphQLObjectType) { return type.getInterfaces(); } } }, possibleTypes: { type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__Type)), resolve: function resolve(type) { if (type instanceof _definition.GraphQLInterfaceType || type instanceof _definition.GraphQLUnionType) { return type.getPossibleTypes(); } } }, enumValues: { type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__EnumValue)), args: { includeDeprecated: { type: _scalars.GraphQLBoolean, defaultValue: false } }, resolve: function resolve(type, _ref2) { var includeDeprecated = _ref2.includeDeprecated; if (type instanceof _definition.GraphQLEnumType) { var valueMap = type.getValues(); var values = _Object$keys(valueMap).map(function (valueName) { return valueMap[valueName]; }); if (!includeDeprecated) { values = values.filter(function (value) { return !value.deprecationReason; }); } return values; } } }, inputFields: { type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__InputValue)), resolve: function resolve(type) { if (type instanceof _definition.GraphQLInputObjectType) { var fieldMap = type.getFields(); return _Object$keys(fieldMap).map(function (fieldName) { return fieldMap[fieldName]; }); } } }, ofType: { type: __Type } }; } }); var __Field = new _definition.GraphQLObjectType({ name: '__Field', fields: function fields() { return { name: { type: new _definition.GraphQLNonNull(_scalars.GraphQLString) }, description: { type: _scalars.GraphQLString }, args: { type: new _definition.GraphQLNonNull(new _definition.GraphQLList(new _definition.GraphQLNonNull(__InputValue))), resolve: function resolve(field) { return field.args == null ? [] : field.args; } }, type: { type: new _definition.GraphQLNonNull(__Type) }, isDeprecated: { type: new _definition.GraphQLNonNull(_scalars.GraphQLBoolean), resolve: function resolve(field) { return !!field.deprecationReason; } }, deprecationReason: { type: _scalars.GraphQLString } }; } }); var __InputValue = new _definition.GraphQLObjectType({ name: '__InputValue', fields: function fields() { return { name: { type: new _definition.GraphQLNonNull(_scalars.GraphQLString) }, description: { type: _scalars.GraphQLString }, type: { type: new _definition.GraphQLNonNull(__Type) }, defaultValue: { type: _scalars.GraphQLString, resolve: function resolve(inputVal) { return inputVal.defaultValue == null ? null : JSON.stringify(inputVal.defaultValue); } } }; } }); var __EnumValue = new _definition.GraphQLObjectType({ name: '__EnumValue', fields: { name: { type: new _definition.GraphQLNonNull(_scalars.GraphQLString) }, description: { type: _scalars.GraphQLString }, isDeprecated: { type: new _definition.GraphQLNonNull(_scalars.GraphQLBoolean), resolve: function resolve(enumValue) { return !!enumValue.deprecationReason; } }, deprecationReason: { type: _scalars.GraphQLString } } }); var TypeKind = { SCALAR: 0, OBJECT: 1, INTERFACE: 2, UNION: 3, ENUM: 4, INPUT_OBJECT: 5, LIST: 6, NON_NULL: 7 }; var __TypeKind = new _definition.GraphQLEnumType({ name: '__TypeKind', description: 'An enum describing what kind of type a given __Type is', values: { SCALAR: { value: TypeKind.SCALAR, description: 'Indicates this type is a scalar.' }, OBJECT: { value: TypeKind.OBJECT, description: 'Indicates this type is an object. ' + '`fields` and `interfaces` are valid fields.' }, INTERFACE: { value: TypeKind.INTERFACE, description: 'Indicates this type is an interface. ' + '`fields` and `possibleTypes` are valid fields.' }, UNION: { value: TypeKind.UNION, description: 'Indicates this type is a union. ' + '`possibleTypes` is a valid field.' }, ENUM: { value: TypeKind.ENUM, description: 'Indicates this type is an enum. ' + '`enumValues` is a valid field.' }, INPUT_OBJECT: { value: TypeKind.INPUT_OBJECT, description: 'Indicates this type is an input object. ' + '`inputFields` is a valid field.' }, LIST: { value: TypeKind.LIST, description: 'Indicates this type is a list. ' + '`ofType` is a valid field.' }, NON_NULL: { value: TypeKind.NON_NULL, description: 'Indicates this type is a non-null. ' + '`ofType` is a valid field.' } } }); /** * Note that these are GraphQLFieldDefinition and not GraphQLFieldConfig, * so the format for args is different. */ var SchemaMetaFieldDef = { name: '__schema', type: new _definition.GraphQLNonNull(__Schema), description: 'Access the current type schema of this server.', args: [], resolve: function resolve(source, args, root, fieldAST, fieldType, parentType, schema) { return schema; } }; exports.SchemaMetaFieldDef = SchemaMetaFieldDef; var TypeMetaFieldDef = { name: '__type', type: __Type, description: 'Request the type information of a single type.', args: [{ name: 'name', type: new _definition.GraphQLNonNull(_scalars.GraphQLString) }], resolve: function resolve(source, _ref3, root, fieldAST, fieldType, parentType, schema) { var name = _ref3.name; return schema.getType(name); } }; exports.TypeMetaFieldDef = TypeMetaFieldDef; var TypeNameMetaFieldDef = { name: '__typename', type: new _definition.GraphQLNonNull(_scalars.GraphQLString), description: 'The name of the current Object type at runtime.', args: [], resolve: function resolve(source, args, root, fieldAST, fieldType, parentType) { return parentType.name; } }; exports.TypeNameMetaFieldDef = TypeNameMetaFieldDef;