|
1 |
| -/** |
2 |
| - * The `g` export is the primary entrypoint into `@graphql-ts/schema` that lets |
3 |
| - * you compose GraphQL types into a GraphQL Schema |
4 |
| - * |
5 |
| - * A simple schema with only a query type looks like this. |
6 |
| - * |
7 |
| - * ```ts |
8 |
| - * import { g } from "@graphql-ts/schema"; |
9 |
| - * import { GraphQLSchema, graphql } from "graphql"; |
10 |
| - * |
11 |
| - * const Query = g.object()({ |
12 |
| - * name: "Query", |
13 |
| - * fields: { |
14 |
| - * hello: g.field({ |
15 |
| - * type: g.String, |
16 |
| - * resolve() { |
17 |
| - * return "Hello!"; |
18 |
| - * }, |
19 |
| - * }), |
20 |
| - * }, |
21 |
| - * }); |
22 |
| - * |
23 |
| - * const schema = new GraphQLSchema({ |
24 |
| - * query: Query.graphQLType, |
25 |
| - * }); |
26 |
| - * |
27 |
| - * graphql({ |
28 |
| - * source: ` |
29 |
| - * query { |
30 |
| - * hello |
31 |
| - * } |
32 |
| - * `, |
33 |
| - * schema, |
34 |
| - * }).then((result) => { |
35 |
| - * console.log(result); |
36 |
| - * }); |
37 |
| - * ``` |
38 |
| - * |
39 |
| - * You can use pass the `graphQLSchema` to `ApolloServer` and other GraphQL servers. |
40 |
| - * |
41 |
| - * You can also create a more advanced schema with other object types, args and mutations. |
42 |
| - * |
43 |
| - * ```ts |
44 |
| - * import { g } from "@graphql-ts/schema"; |
45 |
| - * import { GraphQLSchema, graphql } from "graphql"; |
46 |
| - * import { deepEqual } from "assert"; |
47 |
| - * |
48 |
| - * type TodoItem = { |
49 |
| - * title: string; |
50 |
| - * }; |
51 |
| - * |
52 |
| - * const todos: TodoItem[] = []; |
53 |
| - * |
54 |
| - * const Todo = g.object<TodoItem>({ |
55 |
| - * name: "Todo", |
56 |
| - * fields: { |
57 |
| - * title: g.field({ type: g.String }), |
58 |
| - * }, |
59 |
| - * }); |
60 |
| - * |
61 |
| - * const Query = g.object()({ |
62 |
| - * name: "Query", |
63 |
| - * fields: { |
64 |
| - * todos: g.field({ |
65 |
| - * type: g.list(Todo), |
66 |
| - * resolve() { |
67 |
| - * return todos; |
68 |
| - * }, |
69 |
| - * }), |
70 |
| - * }, |
71 |
| - * }); |
72 |
| - * |
73 |
| - * const Mutation = g.object()({ |
74 |
| - * name: "Mutation", |
75 |
| - * fields: { |
76 |
| - * createTodo: g.field({ |
77 |
| - * args: { |
78 |
| - * title: g.arg({ type: g.String }), |
79 |
| - * }, |
80 |
| - * type: Todo, |
81 |
| - * resolve(source, { title }) { |
82 |
| - * const todo = { title }; |
83 |
| - * todos.push(todo); |
84 |
| - * return todo; |
85 |
| - * }, |
86 |
| - * }), |
87 |
| - * }, |
88 |
| - * }); |
89 |
| - * |
90 |
| - * const schema = new GraphQLSchema({ |
91 |
| - * query: Query.graphQLType, |
92 |
| - * mutation: Mutation.graphQLType, |
93 |
| - * }); |
94 |
| - * |
95 |
| - * (async () => { |
96 |
| - * const result = await graphql({ |
97 |
| - * source: ` |
98 |
| - * query { |
99 |
| - * todos { |
100 |
| - * title |
101 |
| - * } |
102 |
| - * } |
103 |
| - * `, |
104 |
| - * schema, |
105 |
| - * }); |
106 |
| - * deepEqual(result, { data: { todos: [] } }); |
107 |
| - * |
108 |
| - * const result = await graphql({ |
109 |
| - * source: ` |
110 |
| - * mutation { |
111 |
| - * createTodo(title: "Try @graphql-ts/schema") { |
112 |
| - * title |
113 |
| - * } |
114 |
| - * } |
115 |
| - * `, |
116 |
| - * schema, |
117 |
| - * }); |
118 |
| - * deepEqual(result, { |
119 |
| - * data: { createTodo: { title: "Try @graphql-ts/schema" } }, |
120 |
| - * }); |
121 |
| - * |
122 |
| - * const result = await graphql({ |
123 |
| - * source: ` |
124 |
| - * query { |
125 |
| - * todos { |
126 |
| - * title |
127 |
| - * } |
128 |
| - * } |
129 |
| - * `, |
130 |
| - * schema, |
131 |
| - * }); |
132 |
| - * deepEqual(result, { |
133 |
| - * data: { todos: [{ title: "Try @graphql-ts/schema" }] }, |
134 |
| - * }); |
135 |
| - * })(); |
136 |
| - * ``` |
137 |
| - * |
138 |
| - * For information on how to construct other types like input objects, unions, |
139 |
| - * interfaces and enums and more detailed information, see the documentation in |
140 |
| - * the `graphql` export below. |
141 |
| - * |
142 |
| - * When using it, you're going to want to create your own version of it bound to |
143 |
| - * your specific `Context` type. |
144 |
| - * |
145 |
| - * @module |
146 |
| - */ |
147 |
| -import * as g from "."; |
| 1 | +import type * as gInput from "./api-without-context"; |
| 2 | +import type * as gOutput from "./output"; |
| 3 | +import type * as gType from "./type"; |
148 | 4 | export { field, object } from "./api-with-context";
|
149 | 5 | export {
|
150 | 6 | arg,
|
@@ -188,31 +44,35 @@ export { scalar } from "./api-without-context";
|
188 | 44 | */
|
189 | 45 | export type Context = unknown;
|
190 | 46 |
|
191 |
| -export type NullableType = g.NullableType<Context>; |
192 |
| -export type Type = g.Type<Context>; |
193 |
| -export type NullableOutputType = g.NullableOutputType<Context>; |
194 |
| -export type OutputType = g.OutputType<Context>; |
| 47 | +export type NullableType = gType.NullableType<Context>; |
| 48 | +export type Type = gType.Type<Context>; |
| 49 | +export type NullableOutputType = gOutput.NullableOutputType<Context>; |
| 50 | +export type OutputType = gOutput.OutputType<Context>; |
195 | 51 | export type Field<
|
196 | 52 | Source,
|
197 |
| - Args extends Record<string, g.Arg<g.InputType>>, |
| 53 | + Args extends Record<string, gInput.Arg<gInput.InputType>>, |
198 | 54 | TType extends OutputType,
|
199 | 55 | Key extends string
|
200 |
| -> = g.Field<Source, Args, TType, Key, Context>; |
| 56 | +> = gOutput.Field<Source, Args, TType, Key, Context>; |
201 | 57 | export type FieldResolver<
|
202 | 58 | Source,
|
203 |
| - Args extends Record<string, g.Arg<g.InputType>>, |
| 59 | + Args extends Record<string, gInput.Arg<gInput.InputType>>, |
204 | 60 | TType extends OutputType
|
205 |
| -> = g.FieldResolver<Source, Args, TType, Context>; |
206 |
| -export type ObjectType<Source> = g.ObjectType<Source, Context>; |
207 |
| -export type UnionType<Source> = g.UnionType<Source, Context>; |
| 61 | +> = gOutput.FieldResolver<Source, Args, TType, Context>; |
| 62 | +export type ObjectType<Source> = gOutput.ObjectType<Source, Context>; |
| 63 | +export type UnionType<Source> = gOutput.UnionType<Source, Context>; |
208 | 64 | export type InterfaceType<
|
209 | 65 | Source,
|
210 | 66 | Fields extends Record<
|
211 | 67 | string,
|
212 |
| - g.InterfaceField<Record<string, g.Arg<g.InputType>>, OutputType, Context> |
| 68 | + gOutput.InterfaceField< |
| 69 | + Record<string, gInput.Arg<gInput.InputType>>, |
| 70 | + OutputType, |
| 71 | + Context |
| 72 | + > |
213 | 73 | >
|
214 |
| -> = g.InterfaceType<Source, Fields, Context>; |
| 74 | +> = gOutput.InterfaceType<Source, Fields, Context>; |
215 | 75 | export type InterfaceField<
|
216 |
| - Args extends Record<string, g.Arg<g.InputType>>, |
| 76 | + Args extends Record<string, gInput.Arg<gInput.InputType>>, |
217 | 77 | TType extends OutputType
|
218 |
| -> = g.InterfaceField<Args, TType, Context>; |
| 78 | +> = gOutput.InterfaceField<Args, TType, Context>; |
0 commit comments