Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/extend/src/extend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import {
graphqlSync,
printSchema,
} from "graphql";
import { g } from "@graphql-ts/schema";
import { gWithContext } from "@graphql-ts/schema";
import { extend } from ".";

const g = gWithContext();
type g<T> = gWithContext.infer<T>;

const getGql =
(schema: GraphQLSchema) =>
([source]: TemplateStringsArray) =>
Expand Down Expand Up @@ -162,7 +165,7 @@ test("basic mutation with existing mutations", () => {
});

test("errors when query type is used elsewhere in schema", () => {
const Query: g.ObjectType<{}> = g.object<{}>()({
const Query: g<typeof g.object<{}>> = g.object<{}>()({
name: "Query",
fields: () => ({
thing: g.field({
Expand Down Expand Up @@ -200,7 +203,7 @@ test("errors when query type is used elsewhere in schema", () => {
});

test("errors when query and mutation type is used elsewhere in schema", () => {
const Query: g.ObjectType<{}> = g.object<{}>()({
const Query: g<typeof g.object<{}>> = g.object<{}>()({
name: "Query",
fields: () => ({
thing: g.field({
Expand All @@ -211,7 +214,7 @@ test("errors when query and mutation type is used elsewhere in schema", () => {
}),
}),
});
const Mutation: g.ObjectType<{}> = g.object<{}>()({
const Mutation: g<typeof g.object<{}>> = g.object<{}>()({
name: "Mutation",
fields: () => ({
thing: g.field({
Expand Down Expand Up @@ -250,7 +253,7 @@ test("errors when query and mutation type is used elsewhere in schema", () => {
});

test("errors when query and mutation type is used elsewhere in schema", () => {
const Query: g.ObjectType<{}> = g.object<{}>()({
const Query: g<typeof g.object<{}>> = g.object<{}>()({
name: "Query",
fields: () => ({
thing: g.field({
Expand All @@ -273,7 +276,7 @@ test("errors when query and mutation type is used elsewhere in schema", () => {
}),
}),
});
const Mutation: g.ObjectType<{}> = g.object<{}>()({
const Mutation: g<typeof g.object<{}>> = g.object<{}>()({
name: "Mutation",
fields: () => ({
thing: g.field({
Expand Down
5 changes: 2 additions & 3 deletions packages/extend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
} from "graphql";

import {
g,
GField,
GObjectType,
GArg,
Expand Down Expand Up @@ -323,13 +322,13 @@ function flattenExtensions(
`More than one extension defines a field named ${JSON.stringify(
key
)} on the ${operation} type.\nThe first field:\n${printFieldOnType(
g.object()({
new GObjectType({
name: "ForError",
fields: { [key]: val },
}),
key
)}\nThe second field:\n${printFieldOnType(
g.object()({
new GObjectType({
name: "ForError",
fields: { [key]: resolvedExtension[operation][key] },
}),
Expand Down
3 changes: 3 additions & 0 deletions packages/schema/src/g-for-doc-references.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { GWithContext } from "./output";

export declare const g: GWithContext<unknown>;
16 changes: 3 additions & 13 deletions packages/schema/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import type {
InferValueFromArgs,
InferValueFromInputType,
} from "./api-without-context";
import type {
object,
field,
interface as interfaceFunc,
} from "./api-with-context";
import {
GArg,
GEnumType,
Expand Down Expand Up @@ -46,12 +41,7 @@ import {
GraphQLFloat,
GraphQLString,
} from "graphql";

export type __toMakeTypeScriptEmitImportsForItemsOnlyUsedInJSDoc = [
typeof interfaceFunc,
typeof field,
typeof object,
];
import type { g } from "./g-for-doc-references";

type SomeTypeThatIsntARecordOfArgs = string;

Expand Down Expand Up @@ -399,7 +389,7 @@ export type GWithContext<Context> = {
* Creates a GraphQL interface field.
*
* These will generally be passed directly to the `fields` object in a
* {@link interfaceFunc `g.interface`} call. Interfaces fields are similar to
* {@link g.interface} call. Interfaces fields are similar to
* {@link GField regular fields} except that they **don't define how the field
* is resolved**.
*
Expand Down Expand Up @@ -531,7 +521,7 @@ export type GWithContext<Context> = {
) => GInterfaceType<Source, Fields, Context>;
/**
* A shorthand to easily create {@link GEnumValueConfig enum values} to pass to
* {@link enumType `g.enum`}.
* {@link g.enum}.
*
* If you need to set a `description` or `deprecationReason` for an enum
* variant, you should pass values directly to `g.enum` without using
Expand Down
40 changes: 15 additions & 25 deletions packages/schema/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,7 @@ import {
type FieldDefinitionNode,
type InputValueDefinitionNode,
} from "graphql";
import type {
field,
union,
interface as interface_,
object,
} from "./api-with-context";
import type {
scalar,
enum as enum_,
inputObject,
arg,
} from "./api-without-context";
import type { g } from "./g-for-doc-references";

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

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

/**
* A GraphQL output field for an {@link GObjectType object type} which should be
* created using {@link field `g.field`}.
* created using {@link g.field}.
*/
export type GField<
Source,
Expand All @@ -194,7 +183,7 @@ export type GField<

/**
* A GraphQL object type. This should generally be constructed with
* {@link object `g.object`}.
* {@link g.object}.
*
* Note this is an **output** type, if you want an input object, use
* {@link GInputObjectType}.
Expand Down Expand Up @@ -230,7 +219,7 @@ export type GObjectTypeConfig<

/**
* A GraphQL union type. This should generally be constructed with
* {@link union `g.union`}.
* {@link g.union}.
*
* A union type represents an object that could be one of a list of types. Note
* it is similar to an {@link GInterfaceType} except that a union doesn't imply
Expand Down Expand Up @@ -285,7 +274,7 @@ export type GInterfaceField<
/**
* A GraphQL interface type that can be implemented by other
* {@link GObjectType GraphQL object} and interface types. This should generally
* be constructed with {@link interface_ `g.interface`}.
* be constructed with {@link g.interface}.
*
* If you use the `GInterfaceType` constructor directly, all fields will need
* explicit resolvers so you should use `g.interface` instead.
Expand Down Expand Up @@ -330,7 +319,7 @@ export type GInterfaceTypeConfig<
>;

/**
* A GraphQL argument. These should be created with {@link arg `g.arg`}
* A GraphQL argument. These should be created with {@link g.arg}
*
* Args can can be used as arguments on output fields:
*
Expand Down Expand Up @@ -388,7 +377,10 @@ export type GArg<
HasDefaultValue extends boolean = boolean,
> = {
type: Type;
defaultValue: HasDefaultValue extends true ? {} | null : undefined;
defaultValue: {
true: {} | null;
false: undefined;
}[`${HasDefaultValue}`];
description?: Maybe<string>;
deprecationReason?: Maybe<string>;
extensions?: Maybe<GraphQLInputFieldExtensions & GraphQLArgumentExtensions>;
Expand All @@ -412,7 +404,7 @@ export type GInputObjectTypeConfig<

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

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

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

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

/**
* A GraphQL list type. This should generally be constructed with
* {@link list `g.list`}.
* A GraphQL list type. This should generally be constructed with {@link g.list}.
*
* Unlike some other constructors in this module, this constructor functions
* exactly the same as it's counterpart `g.list` so it is safe to use directly
Expand Down
Loading