Skip to content

Commit c25c3ea

Browse files
committed
Rename bindGraphQLSchemaAPIToContext to bindG and include functions that dont need to be bound to context
1 parent 663b3d2 commit c25c3ea

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { GraphQLSchemaAPIWithContext } from "../output";
1+
import { GWithContext } from "../output";
22

3-
declare const __graphql: GraphQLSchemaAPIWithContext<unknown>;
3+
declare const __graphql: GWithContext<unknown>;
44

55
export = __graphql;

packages/schema/src/api-with-context/api-with-context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { bindGraphQLSchemaAPIToContext } from "../output";
1+
import { initG } from "../output";
22

3-
const __graphql = bindGraphQLSchemaAPIToContext();
3+
const __graphql = initG();
44

55
export const { field, fields, interfaceField, object, union } = __graphql;
66

packages/schema/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@
4141
* @module
4242
*/
4343
export * as g from "./schema-api";
44-
export {
45-
bindGraphQLSchemaAPIToContext,
46-
type GraphQLSchemaAPIWithContext,
47-
} from "./output";
44+
export { initG, type GWithContext } from "./output";
4845

4946
export type {
5047
InferValueFromArg,

packages/schema/src/output.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
GraphQLUnionType,
1111
GraphQLUnionTypeConfig,
1212
} from "graphql/type/definition";
13+
import * as withoutContext from "./api-without-context";
1314
import type { InferValueFromArgs } from "./api-without-context";
1415
import type {
1516
object,
@@ -168,7 +169,7 @@ type MergeTuple<T, Merged> = T extends readonly [infer U, ...infer Rest]
168169
? MergeTuple<Rest, Merged & U>
169170
: Merged;
170171

171-
export type GraphQLSchemaAPIWithContext<Context> = {
172+
export type GWithContext<Context> = {
172173
/**
173174
* Creates a GraphQL object type.
174175
*
@@ -549,10 +550,10 @@ export type GraphQLSchemaAPIWithContext<Context> = {
549550
) => GInterfaceType<Source, Fields, Context>;
550551
};
551552

552-
export function bindGraphQLSchemaAPIToContext<
553-
Context,
554-
>(): GraphQLSchemaAPIWithContext<Context> {
553+
export function initG<Context>(): typeof withoutContext &
554+
GWithContext<Context> {
555555
return {
556+
...withoutContext,
556557
object() {
557558
return function objectInner(config) {
558559
return new GObjectType(config);

test-project/index.test-d.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
g,
3-
bindGraphQLSchemaAPIToContext,
3+
initG,
44
Arg,
55
InferValueFromInputType,
66
InputObjectType,
@@ -212,10 +212,7 @@ g.object<{ id: string } | { id: boolean }>()({
212212
});
213213

214214
{
215-
const g = {
216-
...gWithContext,
217-
...bindGraphQLSchemaAPIToContext<{ isAdminUIBuildProcess: true }>(),
218-
};
215+
const g = initG<{ isAdminUIBuildProcess: true }>();
219216

220217
const SomeOutput = g.object<{ thing: boolean }>()({
221218
name: "Something",
@@ -334,11 +331,11 @@ g.object<{ id: string } | { id: boolean }>()({
334331
}
335332

336333
{
337-
const typesWithContextA = bindGraphQLSchemaAPIToContext<{
334+
const typesWithContextA = initG<{
338335
something: boolean;
339336
}>();
340337

341-
const typesWithContextB = bindGraphQLSchemaAPIToContext<{
338+
const typesWithContextB = initG<{
342339
something: boolean;
343340
other: string;
344341
}>();
@@ -1757,7 +1754,7 @@ const someInputFields = {
17571754
>;
17581755
type SourceType = { discriminant: string };
17591756

1760-
const g = bindGraphQLSchemaAPIToContext<Context>();
1757+
const g = initG<Context>();
17611758

17621759
const interfaceType = g.interface<SourceType>()({
17631760
name: "a",
@@ -1767,7 +1764,7 @@ const someInputFields = {
17671764
});
17681765

17691766
const field = g.field({
1770-
type: gWithContext.String,
1767+
type: g.String,
17711768
resolve(x: SourceType) {
17721769
return x.discriminant as string;
17731770
},
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { GraphQLSchemaAPIWithContext } from "@graphql-ts/schema";
1+
import { GWithContext } from "@graphql-ts/schema";
22
import { Context } from ".";
33

4-
declare const __graphql: GraphQLSchemaAPIWithContext<Context>;
4+
declare const __graphql: GWithContext<Context>;
55

66
export = __graphql;

0 commit comments

Comments
 (0)