Skip to content

Commit d06b3bc

Browse files
committed
Try a thing for docsmill
1 parent 8146575 commit d06b3bc

File tree

5 files changed

+171
-163
lines changed

5 files changed

+171
-163
lines changed

packages/schema/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*
4040
* @module
4141
*/
42-
export * as g from "./schema-api";
42+
export * from "./schema-api-export";
4343
export { bindGraphQLSchemaAPIToContext } from "./output";
4444
export type {
4545
Field,
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * as graphql from "./schema-api";
1+
export * as g from "./schema-api";
+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import * as _g from "./schema-api";
2+
3+
/**
4+
* The `g` export is the primary entrypoint into `@graphql-ts/schema` that lets
5+
* you compose GraphQL types into a GraphQL Schema
6+
*
7+
* A simple schema with only a query type looks like this.
8+
*
9+
* ```ts
10+
* import { g } from "@graphql-ts/schema";
11+
* import { GraphQLSchema, graphql } from "graphql";
12+
*
13+
* const Query = g.object()({
14+
* name: "Query",
15+
* fields: {
16+
* hello: g.field({
17+
* type: g.String,
18+
* resolve() {
19+
* return "Hello!";
20+
* },
21+
* }),
22+
* },
23+
* });
24+
*
25+
* const schema = new GraphQLSchema({
26+
* query: Query.graphQLType,
27+
* });
28+
*
29+
* graphql({
30+
* source: `
31+
* query {
32+
* hello
33+
* }
34+
* `,
35+
* schema,
36+
* }).then((result) => {
37+
* console.log(result);
38+
* });
39+
* ```
40+
*
41+
* You can use pass the `graphQLSchema` to `ApolloServer` and other GraphQL servers.
42+
*
43+
* You can also create a more advanced schema with other object types, args and mutations.
44+
*
45+
* ```ts
46+
* import { g } from "@graphql-ts/schema";
47+
* import { GraphQLSchema, graphql } from "graphql";
48+
* import { deepEqual } from "assert";
49+
*
50+
* type TodoItem = {
51+
* title: string;
52+
* };
53+
*
54+
* const todos: TodoItem[] = [];
55+
*
56+
* const Todo = g.object<TodoItem>({
57+
* name: "Todo",
58+
* fields: {
59+
* title: g.field({ type: g.String }),
60+
* },
61+
* });
62+
*
63+
* const Query = g.object()({
64+
* name: "Query",
65+
* fields: {
66+
* todos: g.field({
67+
* type: g.list(Todo),
68+
* resolve() {
69+
* return todos;
70+
* },
71+
* }),
72+
* },
73+
* });
74+
*
75+
* const Mutation = g.object()({
76+
* name: "Mutation",
77+
* fields: {
78+
* createTodo: g.field({
79+
* args: {
80+
* title: g.arg({ type: g.String }),
81+
* },
82+
* type: Todo,
83+
* resolve(source, { title }) {
84+
* const todo = { title };
85+
* todos.push(todo);
86+
* return todo;
87+
* },
88+
* }),
89+
* },
90+
* });
91+
*
92+
* const schema = new GraphQLSchema({
93+
* query: Query.graphQLType,
94+
* mutation: Mutation.graphQLType,
95+
* });
96+
*
97+
* (async () => {
98+
* const result = await graphql({
99+
* source: `
100+
* query {
101+
* todos {
102+
* title
103+
* }
104+
* }
105+
* `,
106+
* schema,
107+
* });
108+
* deepEqual(result, { data: { todos: [] } });
109+
*
110+
* const result = await graphql({
111+
* source: `
112+
* mutation {
113+
* createTodo(title: "Try @graphql-ts/schema") {
114+
* title
115+
* }
116+
* }
117+
* `,
118+
* schema,
119+
* });
120+
* deepEqual(result, {
121+
* data: { createTodo: { title: "Try @graphql-ts/schema" } },
122+
* });
123+
*
124+
* const result = await graphql({
125+
* source: `
126+
* query {
127+
* todos {
128+
* title
129+
* }
130+
* }
131+
* `,
132+
* schema,
133+
* });
134+
* deepEqual(result, {
135+
* data: { todos: [{ title: "Try @graphql-ts/schema" }] },
136+
* });
137+
* })();
138+
* ```
139+
*
140+
* For information on how to construct other types like input objects, unions,
141+
* interfaces and enums and more detailed information, see the documentation in
142+
* the `g` export below.
143+
*
144+
* When using it, you're going to want to create your own version of it bound to
145+
* your specific `Context` type.
146+
*/
147+
export import g = _g;
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as g from "./schema-api";

packages/schema/src/schema-api.ts

+21-161
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,6 @@
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";
1484
export { field, object } from "./api-with-context";
1495
export {
1506
arg,
@@ -188,31 +44,35 @@ export { scalar } from "./api-without-context";
18844
*/
18945
export type Context = unknown;
19046

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>;
19551
export type Field<
19652
Source,
197-
Args extends Record<string, g.Arg<g.InputType>>,
53+
Args extends Record<string, gInput.Arg<gInput.InputType>>,
19854
TType extends OutputType,
19955
Key extends string
200-
> = g.Field<Source, Args, TType, Key, Context>;
56+
> = gOutput.Field<Source, Args, TType, Key, Context>;
20157
export type FieldResolver<
20258
Source,
203-
Args extends Record<string, g.Arg<g.InputType>>,
59+
Args extends Record<string, gInput.Arg<gInput.InputType>>,
20460
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>;
20864
export type InterfaceType<
20965
Source,
21066
Fields extends Record<
21167
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+
>
21373
>
214-
> = g.InterfaceType<Source, Fields, Context>;
74+
> = gOutput.InterfaceType<Source, Fields, Context>;
21575
export type InterfaceField<
216-
Args extends Record<string, g.Arg<g.InputType>>,
76+
Args extends Record<string, gInput.Arg<gInput.InputType>>,
21777
TType extends OutputType
218-
> = g.InterfaceField<Args, TType, Context>;
78+
> = gOutput.InterfaceField<Args, TType, Context>;

0 commit comments

Comments
 (0)