| 'use strict'; |
|
|
| Object.defineProperty(exports, '__esModule', { value: true }); |
|
|
| var apiWithContext = require('./api-with-context-c4c7de9f.cjs.prod.js'); |
| var listAndNonNull = require('./list-and-non-null-509803e9.cjs.prod.js'); |
| require('graphql/type/definition'); |
| require('graphql/type/scalars'); |
|
|
| /** |
| * The `graphql` export is the primary entrypoint into `@graphql-ts/schema` that |
| * lets you compose GraphQL types into a GraphQL Schema |
| * |
| * A simple schema with only a query type looks like this. |
| * |
| * ```ts |
| * import { graphql } from "@graphql-ts/schema"; |
| * import { GraphQLSchema, graphql as runGraphQL } from "graphql"; |
| * |
| * const Query = graphql.object()({ |
| * name: "Query", |
| * fields: { |
| * hello: graphql.field({ |
| * type: graphql.String, |
| * resolve() { |
| * return "Hello!"; |
| * }, |
| * }), |
| * }, |
| * }); |
| * |
| * const schema = new GraphQLSchema({ |
| * query: Query.graphQLType, |
| * }); |
| * |
| * runGraphQL({ |
| * source: ` |
| * query { |
| * hello |
| * } |
| * `, |
| * schema, |
| * }).then((result) => { |
| * console.log(result); |
| * }); |
| * ``` |
| * |
| * You can use pass the `graphQLSchema` to `ApolloServer` and other GraphQL servers. |
| * |
| * You can also create a more advanced schema with other object types, args and mutations. |
| * |
| * ```ts |
| * import { graphql } from "@graphql-ts/schema"; |
| * import { GraphQLSchema, graphql as runGraphQL } from "graphql"; |
| * import { deepEqual } from "assert"; |
| * |
| * type TodoItem = { |
| * title: string; |
| * }; |
| * |
| * const todos: TodoItem[] = []; |
| * |
| * const Todo = graphql.object<TodoItem>({ |
| * name: "Todo", |
| * fields: { |
| * title: graphql.field({ type: graphql.String }), |
| * }, |
| * }); |
| * |
| * const Query = graphql.object()({ |
| * name: "Query", |
| * fields: { |
| * todos: graphql.field({ |
| * type: graphql.list(Todo), |
| * resolve() { |
| * return todos; |
| * }, |
| * }), |
| * }, |
| * }); |
| * |
| * const Mutation = graphql.object()({ |
| * name: "Mutation", |
| * fields: { |
| * createTodo: graphql.field({ |
| * args: { |
| * title: graphql.arg({ type: graphql.String }), |
| * }, |
| * type: Todo, |
| * resolve(source, { title }) { |
| * const todo = { title }; |
| * todos.push(todo); |
| * return todo; |
| * }, |
| * }), |
| * }, |
| * }); |
| * |
| * const schema = new GraphQLSchema({ |
| * query: Query.graphQLType, |
| * mutation: Mutation.graphQLType, |
| * }); |
| * |
| * (async () => { |
| * const result = await runGraphQL({ |
| * source: ` |
| * query { |
| * todos { |
| * title |
| * } |
| * } |
| * `, |
| * schema, |
| * }); |
| * deepEqual(result, { data: { todos: [] } }); |
| * |
| * const result = await runGraphQL({ |
| * source: ` |
| * mutation { |
| * createTodo(title: "Try @graphql-ts/schema") { |
| * title |
| * } |
| * } |
| * `, |
| * schema, |
| * }); |
| * deepEqual(result, { |
| * data: { createTodo: { title: "Try @graphql-ts/schema" } }, |
| * }); |
| * |
| * const result = await runGraphQL({ |
| * source: ` |
| * query { |
| * todos { |
| * title |
| * } |
| * } |
| * `, |
| * schema, |
| * }); |
| * deepEqual(result, { |
| * data: { todos: [{ title: "Try @graphql-ts/schema" }] }, |
| * }); |
| * })(); |
| * ``` |
| * |
| * For information on how to construct other types like input objects, unions, |
| * interfaces and enums and more detailed information, see the documentation in |
| * the `graphql` export below. |
| * |
| * When using it, you're going to want to create your own version of it bound to |
| * your specific `Context` type. |
| * |
| * @module |
| */ |
| /** |
| * The particular `Context` type for this `graphql` export that is provided to |
| * field resolvers. |
| * |
| * Below, there are many types exported which are similar to the types with the |
| * same names exported from the root of the package except that they are bound |
| * to the `Context` type so they can be used elsewhere without needing to be |
| * bound to the context on every usage. |
| */ |
|
|
| var schemaApi = /*#__PURE__*/Object.freeze({ |
| __proto__: null, |
| field: apiWithContext.field, |
| object: apiWithContext.object, |
| arg: listAndNonNull.arg, |
| Boolean: listAndNonNull.Boolean, |
| Float: listAndNonNull.Float, |
| ID: listAndNonNull.ID, |
| Int: listAndNonNull.Int, |
| String: listAndNonNull.String, |
| inputObject: listAndNonNull.inputObject, |
| list: listAndNonNull.list, |
| nonNull: listAndNonNull.nonNull, |
| 'enum': listAndNonNull.enumType, |
| enumValues: listAndNonNull.enumValues, |
| fields: apiWithContext.fields, |
| 'interface': apiWithContext.interfaceType, |
| interfaceField: apiWithContext.interfaceField, |
| union: apiWithContext.union, |
| scalar: listAndNonNull.scalar |
| }); |
|
|
| exports.bindGraphQLSchemaAPIToContext = apiWithContext.bindGraphQLSchemaAPIToContext; |
| exports.graphql = schemaApi; |