Skip to content

Commit

Permalink
feature: update deno
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Jul 2, 2021
1 parent 95a74bb commit 382775e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 65 deletions.
2 changes: 1 addition & 1 deletion docs/plugins/relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ you are using the auth plugin.

The `relayOptions` object passed to builder can contain the following properties:

- `clientMutationId`: `required` (default) | `omit` | | `optional`. Determins if clientMutationId
- `clientMutationId`: `required` (default) | `omit` | `optional`. Determins if clientMutationId
fields are created on connections, and if they are required.
- `nodeQueryOptions`: Options for the `node` field on the query object
- `nodesQueryOptions`: Options for the `nodes` field on the query object
Expand Down
37 changes: 16 additions & 21 deletions packages/deno/packages/plugin-relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ import RelayPlugin from '@giraphql/plugin-relay';
const builder = new SchemaBuilder({
plugins: [RelayPlugin],
relayOptions: {
nodeQueryOptions: {},
nodesQueryOptions: {},
nodeTypeOptions: {},
pageInfoTypeOptions: {},
clientMutationIdFieldOptions: {},
clientMutationIdInputOptions: {},
mutationInputArgOptions: {},
clientMutationId: 'omit',
},
});
```
Expand All @@ -34,10 +28,20 @@ GiraphQL API, options objects are required because other plugins may contribute
These options objects will enable things like defining auth policies for your node query fields if
you are using the auth plugin.

`clientMutationIdFieldOptions`, `clientMutationIdInputOptions`, and `mutationInputArgOptions` are
currently typed as optional because they were added in a non-major version. If they are omitted, a
runtime error will be raised when using the `relayMutationField` method. These options will become
required in the next major version.
### Options

The `relayOptions` object passed to builder can contain the following properties:

- `clientMutationId`: `required` (default) | `omit` | `optional`. Determins if clientMutationId
fields are created on connections, and if they are required.
- `nodeQueryOptions`: Options for the `node` field on the query object
- `nodesQueryOptions`: Options for the `nodes` field on the query object
- `nodeTypeOptions`: Options for the `Node` interface type
- `pageInfoTypeOptions`: Options for the `TypeInfo` object type
- `clientMutationIdFieldOptions`: Options for the `clientMutationId` field on connection objects
- `clientMutationIdInputOptions`: Options for the `clientMutationId` input field on connections
fields
- `mutationInputArgOptions`: Options for the Input object created for each connection field

### Global IDs

Expand Down Expand Up @@ -370,10 +374,6 @@ import '@giraphql/plugin-relay';
const builder = new SchemaBuilder({
plugins: ['GiraphQLRelay'],
relayOptions: {
nodeQueryOptions: {},
nodesQueryOptions: {},
nodeTypeOptions: {},
pageInfoTypeOptions: {},
encodeGlobalID: (typename: string, id: string | number | bigint) => `${typename}:${id}`,
decodeGlobalID: (globalID: string) => {
const [typename, id] = globalID.split(':');
Expand Down Expand Up @@ -419,12 +419,7 @@ const builder = new SchemaBuilder<{
};
}>({
plugins: ['GiraphQLRelay'],
relayOptions: {
nodeQueryOptions: {},
nodesQueryOptions: {},
nodeTypeOptions: {},
pageInfoTypeOptions: {},
},
relayOptions: {},
});
```

Expand Down
35 changes: 19 additions & 16 deletions packages/deno/packages/plugin-relay/schema-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,36 @@ schemaBuilderProto.globalConnectionFields = function globalConnectionFields(fiel
};
const mutationIdCache = createContextCache(() => new Map<string, string>());
schemaBuilderProto.relayMutationField = function relayMutationField(fieldName, { name: inputName = `${capitalize(fieldName)}Input`, argName = "input", inputFields, ...inputOptions }, { resolve, ...fieldOptions }, { name: payloadName = `${capitalize(fieldName)}Payload`, outputFields, interfaces, ...paylaodOptions }) {
const { relayOptions: { clientMutationIdInputOptions, clientMutationIdFieldOptions, mutationInputArgOptions, }, } = this.options;
if (!mutationInputArgOptions) {
throw new Error("relayOptions.mutationInputArgOptions must be set in builder options to use `relayMutationField`");
}
if (!clientMutationIdInputOptions) {
throw new Error("relayOptions.clientMutationIdInputOptions must be set in builder options to use `relayMutationField`");
}
if (!clientMutationIdFieldOptions) {
throw new Error("relayOptions.clientMutationIdFieldOptions must be set in builder options to use `relayMutationField`");
}
const { relayOptions: { clientMutationIdInputOptions = {} as never, clientMutationIdFieldOptions = {} as never, mutationInputArgOptions = {} as never, }, } = this.options;
const includeClientMutationId = this.options.relayOptions.clientMutationId !== "omit";
const inputRef = this.inputType(inputName, {
...inputOptions,
fields: (t) => ({
...inputFields(t),
clientMutationId: t.id({ ...clientMutationIdInputOptions, required: true }),
...(includeClientMutationId
? {
clientMutationId: t.id({
...clientMutationIdInputOptions,
required: this.options.relayOptions.clientMutationId !== "optional",
}),
}
: {}),
}),
});
const payloadRef = this.objectRef<unknown>(payloadName).implement({
...paylaodOptions,
interfaces: interfaces as never,
fields: (t) => ({
...(outputFields as ObjectFieldsShape<SchemaTypes, unknown>)(t),
clientMutationId: t.id({
...clientMutationIdFieldOptions,
nullable: false,
resolve: (parent, args, context, info) => mutationIdCache(context).get(String(info.path.prev!.key))!,
}),
...(includeClientMutationId
? {
clientMutationId: t.id({
...clientMutationIdFieldOptions,
nullable: this.options.relayOptions.clientMutationId === "optional",
resolve: (parent, args, context, info) => mutationIdCache(context).get(String(info.path.prev!.key))!,
}),
}
: {}),
}),
});
this.mutationField(fieldName, (t) => t.field({
Expand Down
13 changes: 7 additions & 6 deletions packages/deno/packages/plugin-relay/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @ts-nocheck
import { GraphQLResolveInfo } from 'https://cdn.skypack.dev/graphql?dts';
import { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRequiredness, InputFieldMap, InputFieldRef, InputFieldsFromShape, InputRef, InputShape, InputShapeFromFields, inputShapeKey, InterfaceParam, MaybePromise, ObjectFieldsShape, ObjectParam, ObjectRef, ObjectTypeOptions, OutputRef, OutputRefShape, OutputShape, OutputType, ParentShape, Resolver, SchemaTypes, ShapeFromTypeParam, } from '../core/index.ts';
export interface RelayPluginOptions<Types extends SchemaTypes> {
import { EmptyToOptional, FieldKind, FieldNullability, FieldOptionsFromKind, FieldRequiredness, InputFieldMap, InputFieldRef, InputFieldsFromShape, InputRef, InputShape, InputShapeFromFields, inputShapeKey, InterfaceParam, MaybePromise, ObjectFieldsShape, ObjectParam, ObjectRef, ObjectTypeOptions, OutputRef, OutputRefShape, OutputShape, OutputType, ParentShape, Resolver, SchemaTypes, ShapeFromTypeParam, } from '../core/index.ts';
export type RelayPluginOptions<Types extends SchemaTypes> = EmptyToOptional<{
clientMutationId?: "omit" | "optional" | "required";
nodeTypeOptions: Omit<GiraphQLSchemaTypes.ObjectTypeOptions<Types, unknown>, "fields">;
pageInfoTypeOptions: Omit<GiraphQLSchemaTypes.ObjectTypeOptions<Types, PageInfoShape>, "fields">;
nodeQueryOptions: Omit<GiraphQLSchemaTypes.QueryFieldOptions<Types, ObjectRef<PageInfoShape>, true, {
Expand All @@ -10,15 +11,15 @@ export interface RelayPluginOptions<Types extends SchemaTypes> {
nodesQueryOptions: Omit<GiraphQLSchemaTypes.QueryFieldOptions<Types, ObjectRef<PageInfoShape>, true, {
ids: InputFieldRef<InputShape<Types, "ID">[]>;
}, Promise<unknown>[]>, "args" | "nullable" | "resolve" | "type">;
mutationInputArgOptions?: Omit<GiraphQLSchemaTypes.ArgFieldOptions<Types, InputRef<{}>, true>, "fields" | "required" | "type">;
clientMutationIdInputOptions?: Omit<GiraphQLSchemaTypes.InputObjectFieldOptions<Types, InputRef<Types["Scalars"]["ID"]["Input"]>, true>, "args" | "nullable" | "resolve" | "type">;
clientMutationIdFieldOptions?: Omit<GiraphQLSchemaTypes.ObjectFieldOptions<Types, {}, OutputRef<Types["Scalars"]["ID"]["Output"]>, false, {}, Types["Scalars"]["ID"]["Output"]>, "args" | "nullable" | "resolve" | "type">;
mutationInputArgOptions: Omit<GiraphQLSchemaTypes.ArgFieldOptions<Types, InputRef<{}>, true>, "fields" | "required" | "type">;
clientMutationIdInputOptions: Omit<GiraphQLSchemaTypes.InputObjectFieldOptions<Types, InputRef<Types["Scalars"]["ID"]["Input"]>, true>, "args" | "nullable" | "resolve" | "type">;
clientMutationIdFieldOptions: Omit<GiraphQLSchemaTypes.ObjectFieldOptions<Types, {}, OutputRef<Types["Scalars"]["ID"]["Output"]>, false, {}, Types["Scalars"]["ID"]["Output"]>, "args" | "nullable" | "resolve" | "type">;
encodeGlobalID?: (typename: string, id: bigint | number | string) => string;
decodeGlobalID?: (globalID: string) => {
typename: string;
id: string;
};
}
}>;
export interface PageInfoShape {
hasNextPage: boolean;
hasPreviousPage: boolean;
Expand Down
37 changes: 16 additions & 21 deletions packages/plugin-relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ import RelayPlugin from '@giraphql/plugin-relay';
const builder = new SchemaBuilder({
plugins: [RelayPlugin],
relayOptions: {
nodeQueryOptions: {},
nodesQueryOptions: {},
nodeTypeOptions: {},
pageInfoTypeOptions: {},
clientMutationIdFieldOptions: {},
clientMutationIdInputOptions: {},
mutationInputArgOptions: {},
clientMutationId: 'omit',
},
});
```
Expand All @@ -34,10 +28,20 @@ GiraphQL API, options objects are required because other plugins may contribute
These options objects will enable things like defining auth policies for your node query fields if
you are using the auth plugin.

`clientMutationIdFieldOptions`, `clientMutationIdInputOptions`, and `mutationInputArgOptions` are
currently typed as optional because they were added in a non-major version. If they are omitted, a
runtime error will be raised when using the `relayMutationField` method. These options will become
required in the next major version.
### Options

The `relayOptions` object passed to builder can contain the following properties:

- `clientMutationId`: `required` (default) | `omit` | `optional`. Determins if clientMutationId
fields are created on connections, and if they are required.
- `nodeQueryOptions`: Options for the `node` field on the query object
- `nodesQueryOptions`: Options for the `nodes` field on the query object
- `nodeTypeOptions`: Options for the `Node` interface type
- `pageInfoTypeOptions`: Options for the `TypeInfo` object type
- `clientMutationIdFieldOptions`: Options for the `clientMutationId` field on connection objects
- `clientMutationIdInputOptions`: Options for the `clientMutationId` input field on connections
fields
- `mutationInputArgOptions`: Options for the Input object created for each connection field

### Global IDs

Expand Down Expand Up @@ -370,10 +374,6 @@ import '@giraphql/plugin-relay';
const builder = new SchemaBuilder({
plugins: ['GiraphQLRelay'],
relayOptions: {
nodeQueryOptions: {},
nodesQueryOptions: {},
nodeTypeOptions: {},
pageInfoTypeOptions: {},
encodeGlobalID: (typename: string, id: string | number | bigint) => `${typename}:${id}`,
decodeGlobalID: (globalID: string) => {
const [typename, id] = globalID.split(':');
Expand Down Expand Up @@ -419,12 +419,7 @@ const builder = new SchemaBuilder<{
};
}>({
plugins: ['GiraphQLRelay'],
relayOptions: {
nodeQueryOptions: {},
nodesQueryOptions: {},
nodeTypeOptions: {},
pageInfoTypeOptions: {},
},
relayOptions: {},
});
```

Expand Down

0 comments on commit 382775e

Please sign in to comment.