Skip to content

Commit 316504d

Browse files
committed
Rename bindGraphQLSchemaAPIToContext to bindG and include functions that dont need to be bound to context
1 parent 5eafeea commit 316504d

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 {
5047
GObjectType,

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,
@@ -210,10 +210,7 @@ g.object<{ id: string } | { id: boolean }>()({
210210
});
211211

212212
{
213-
const g = {
214-
...gWithContext,
215-
...bindGraphQLSchemaAPIToContext<{ isAdminUIBuildProcess: true }>(),
216-
};
213+
const g = initG<{ isAdminUIBuildProcess: true }>();
217214

218215
const SomeOutput = g.object<{ thing: boolean }>()({
219216
name: "Something",
@@ -332,11 +329,11 @@ g.object<{ id: string } | { id: boolean }>()({
332329
}
333330

334331
{
335-
const typesWithContextA = bindGraphQLSchemaAPIToContext<{
332+
const typesWithContextA = initG<{
336333
something: boolean;
337334
}>();
338335

339-
const typesWithContextB = bindGraphQLSchemaAPIToContext<{
336+
const typesWithContextB = initG<{
340337
something: boolean;
341338
other: string;
342339
}>();
@@ -1755,7 +1752,7 @@ const someInputFields = {
17551752
>;
17561753
type SourceType = { discriminant: string };
17571754

1758-
const g = bindGraphQLSchemaAPIToContext<Context>();
1755+
const g = initG<Context>();
17591756

17601757
const interfaceType = g.interface<SourceType>()({
17611758
name: "a",
@@ -1765,7 +1762,7 @@ const someInputFields = {
17651762
});
17661763

17671764
const field = g.field({
1768-
type: gWithContext.String,
1765+
type: g.String,
17691766
resolve(x: SourceType) {
17701767
return x.discriminant as string;
17711768
},
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)