Skip to content

Commit 5c66faf

Browse files
authored
Remove usages of deprecated APIs in non-deprecated APIs and tests (#48)
1 parent 09346e7 commit 5c66faf

File tree

10 files changed

+113
-207
lines changed

10 files changed

+113
-207
lines changed

packages/extend/src/extend.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import {
44
graphqlSync,
55
printSchema,
66
} from "graphql";
7-
import { g } from "@graphql-ts/schema";
7+
import { gWithContext } from "@graphql-ts/schema";
88
import { extend } from ".";
99

10+
const g = gWithContext();
11+
type g<T> = gWithContext.infer<T>;
12+
1013
const getGql =
1114
(schema: GraphQLSchema) =>
1215
([source]: TemplateStringsArray) =>
@@ -162,7 +165,7 @@ test("basic mutation with existing mutations", () => {
162165
});
163166

164167
test("errors when query type is used elsewhere in schema", () => {
165-
const Query: g.ObjectType<{}> = g.object<{}>()({
168+
const Query: g<typeof g.object<{}>> = g.object<{}>()({
166169
name: "Query",
167170
fields: () => ({
168171
thing: g.field({
@@ -200,7 +203,7 @@ test("errors when query type is used elsewhere in schema", () => {
200203
});
201204

202205
test("errors when query and mutation type is used elsewhere in schema", () => {
203-
const Query: g.ObjectType<{}> = g.object<{}>()({
206+
const Query: g<typeof g.object<{}>> = g.object<{}>()({
204207
name: "Query",
205208
fields: () => ({
206209
thing: g.field({
@@ -211,7 +214,7 @@ test("errors when query and mutation type is used elsewhere in schema", () => {
211214
}),
212215
}),
213216
});
214-
const Mutation: g.ObjectType<{}> = g.object<{}>()({
217+
const Mutation: g<typeof g.object<{}>> = g.object<{}>()({
215218
name: "Mutation",
216219
fields: () => ({
217220
thing: g.field({
@@ -250,7 +253,7 @@ test("errors when query and mutation type is used elsewhere in schema", () => {
250253
});
251254

252255
test("errors when query and mutation type is used elsewhere in schema", () => {
253-
const Query: g.ObjectType<{}> = g.object<{}>()({
256+
const Query: g<typeof g.object<{}>> = g.object<{}>()({
254257
name: "Query",
255258
fields: () => ({
256259
thing: g.field({
@@ -273,7 +276,7 @@ test("errors when query and mutation type is used elsewhere in schema", () => {
273276
}),
274277
}),
275278
});
276-
const Mutation: g.ObjectType<{}> = g.object<{}>()({
279+
const Mutation: g<typeof g.object<{}>> = g.object<{}>()({
277280
name: "Mutation",
278281
fields: () => ({
279282
thing: g.field({

packages/extend/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
} from "graphql";
3030

3131
import {
32-
g,
3332
GField,
3433
GObjectType,
3534
GArg,
@@ -323,13 +322,13 @@ function flattenExtensions(
323322
`More than one extension defines a field named ${JSON.stringify(
324323
key
325324
)} on the ${operation} type.\nThe first field:\n${printFieldOnType(
326-
g.object()({
325+
new GObjectType({
327326
name: "ForError",
328327
fields: { [key]: val },
329328
}),
330329
key
331330
)}\nThe second field:\n${printFieldOnType(
332-
g.object()({
331+
new GObjectType({
333332
name: "ForError",
334333
fields: { [key]: resolvedExtension[operation][key] },
335334
}),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { GWithContext } from "./output";
2+
3+
export declare const g: GWithContext<unknown>;

packages/schema/src/output.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ import type {
1111
InferValueFromArgs,
1212
InferValueFromInputType,
1313
} from "./api-without-context";
14-
import type {
15-
object,
16-
field,
17-
interface as interfaceFunc,
18-
} from "./api-with-context";
1914
import {
2015
GArg,
2116
GEnumType,
@@ -46,12 +41,7 @@ import {
4641
GraphQLFloat,
4742
GraphQLString,
4843
} from "graphql";
49-
50-
export type __toMakeTypeScriptEmitImportsForItemsOnlyUsedInJSDoc = [
51-
typeof interfaceFunc,
52-
typeof field,
53-
typeof object,
54-
];
44+
import type { g } from "./g-for-doc-references";
5545

5646
type SomeTypeThatIsntARecordOfArgs = string;
5747

@@ -399,7 +389,7 @@ export type GWithContext<Context> = {
399389
* Creates a GraphQL interface field.
400390
*
401391
* These will generally be passed directly to the `fields` object in a
402-
* {@link interfaceFunc `g.interface`} call. Interfaces fields are similar to
392+
* {@link g.interface} call. Interfaces fields are similar to
403393
* {@link GField regular fields} except that they **don't define how the field
404394
* is resolved**.
405395
*
@@ -531,7 +521,7 @@ export type GWithContext<Context> = {
531521
) => GInterfaceType<Source, Fields, Context>;
532522
/**
533523
* A shorthand to easily create {@link GEnumValueConfig enum values} to pass to
534-
* {@link enumType `g.enum`}.
524+
* {@link g.enum}.
535525
*
536526
* If you need to set a `description` or `deprecationReason` for an enum
537527
* variant, you should pass values directly to `g.enum` without using

packages/schema/src/types.d.ts

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,7 @@ import {
2929
type FieldDefinitionNode,
3030
type InputValueDefinitionNode,
3131
} from "graphql";
32-
import type {
33-
field,
34-
union,
35-
interface as interface_,
36-
object,
37-
} from "./api-with-context";
38-
import type {
39-
scalar,
40-
enum as enum_,
41-
inputObject,
42-
arg,
43-
} from "./api-without-context";
32+
import type { g } from "./g-for-doc-references";
4433

4534
type Maybe<T> = T | null | undefined;
4635

@@ -173,7 +162,7 @@ export type InferValueFromInputType<Type extends GInputType> =
173162

174163
/**
175164
* A GraphQL output field for an {@link GObjectType object type} which should be
176-
* created using {@link field `g.field`}.
165+
* created using {@link g.field}.
177166
*/
178167
export type GField<
179168
Source,
@@ -194,7 +183,7 @@ export type GField<
194183

195184
/**
196185
* A GraphQL object type. This should generally be constructed with
197-
* {@link object `g.object`}.
186+
* {@link g.object}.
198187
*
199188
* Note this is an **output** type, if you want an input object, use
200189
* {@link GInputObjectType}.
@@ -230,7 +219,7 @@ export type GObjectTypeConfig<
230219

231220
/**
232221
* A GraphQL union type. This should generally be constructed with
233-
* {@link union `g.union`}.
222+
* {@link g.union}.
234223
*
235224
* A union type represents an object that could be one of a list of types. Note
236225
* it is similar to an {@link GInterfaceType} except that a union doesn't imply
@@ -285,7 +274,7 @@ export type GInterfaceField<
285274
/**
286275
* A GraphQL interface type that can be implemented by other
287276
* {@link GObjectType GraphQL object} and interface types. This should generally
288-
* be constructed with {@link interface_ `g.interface`}.
277+
* be constructed with {@link g.interface}.
289278
*
290279
* If you use the `GInterfaceType` constructor directly, all fields will need
291280
* explicit resolvers so you should use `g.interface` instead.
@@ -330,7 +319,7 @@ export type GInterfaceTypeConfig<
330319
>;
331320

332321
/**
333-
* A GraphQL argument. These should be created with {@link arg `g.arg`}
322+
* A GraphQL argument. These should be created with {@link g.arg}
334323
*
335324
* Args can can be used as arguments on output fields:
336325
*
@@ -388,7 +377,10 @@ export type GArg<
388377
HasDefaultValue extends boolean = boolean,
389378
> = {
390379
type: Type;
391-
defaultValue: HasDefaultValue extends true ? {} | null : undefined;
380+
defaultValue: {
381+
true: {} | null;
382+
false: undefined;
383+
}[`${HasDefaultValue}`];
392384
description?: Maybe<string>;
393385
deprecationReason?: Maybe<string>;
394386
extensions?: Maybe<GraphQLInputFieldExtensions & GraphQLArgumentExtensions>;
@@ -412,7 +404,7 @@ export type GInputObjectTypeConfig<
412404

413405
/**
414406
* A GraphQL input object type. This should generally be constructed with
415-
* {@link inputObject `g.inputObject`}.
407+
* {@link g.inputObject}.
416408
*
417409
* Unlike some other constructors in this module, this constructor functions
418410
* exactly the same as it's counterpart `g.inputObject` so it is safe to use
@@ -450,8 +442,7 @@ export type GEnumTypeConfig<Values extends { [key: string]: unknown }> =
450442
>;
451443

452444
/**
453-
* A GraphQL enum type. This should generally be constructed with
454-
* {@link enum_ `g.enum`}.
445+
* A GraphQL enum type. This should generally be constructed with {@link g.enum}.
455446
*
456447
* Unlike some other constructors in this module, this constructor functions
457448
* exactly the same as it's counterpart `g.enum` so it is safe to use directly
@@ -470,7 +461,7 @@ export class GEnumType<
470461

471462
/**
472463
* A GraphQL enum type. This should generally be constructed with
473-
* {@link scalar `g.scalar`}.
464+
* {@link g.scalar}.
474465
*
475466
* Unlike some other constructors in this module, this constructor functions
476467
* exactly the same as it's counterpart `g.scalar` so it is safe to use directly
@@ -491,7 +482,7 @@ type Flatten<T> = {
491482

492483
/**
493484
* A GraphQL non-null type. This should generally be constructed with
494-
* {@link enum_ `g.nonNull`}.
485+
* {@link g.nonNull}.
495486
*
496487
* Unlike some other constructors in this module, this constructor functions
497488
* exactly the same as it's counterpart `g.nonNull` so it is safe to use
@@ -528,8 +519,7 @@ export class GNonNull<
528519
}
529520

530521
/**
531-
* A GraphQL list type. This should generally be constructed with
532-
* {@link list `g.list`}.
522+
* A GraphQL list type. This should generally be constructed with {@link g.list}.
533523
*
534524
* Unlike some other constructors in this module, this constructor functions
535525
* exactly the same as it's counterpart `g.list` so it is safe to use directly

0 commit comments

Comments
 (0)