Skip to content

Commit

Permalink
5.4.1 generation of SDK and clients possible due to crucial change in…
Browse files Browse the repository at this point in the history
… thunderOptions position for scalars argument
  • Loading branch information
aexol committed May 8, 2024
1 parent e08907f commit 669db69
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/typescript-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-node",
"version": "1.2.0",
"version": "1.2.1",
"description": "",
"private": true,
"main": "index.js",
Expand Down
35 changes: 22 additions & 13 deletions packages/graphql-zeus-core/TreeToTS/functions/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export const InternalsBuildQuery = ({
};
export const Thunder =
(fn: FetchFunction) =>
<O extends keyof typeof Ops, SCLR extends ScalarDefinition, R extends keyof ValueTypes = GenericOperation<O>>(
<SCLR extends ScalarDefinition>(fn: FetchFunction, thunderGraphQLOptions?: ThunderGraphQLOptions<SCLR>) =>
<O extends keyof typeof Ops, R extends keyof ValueTypes = GenericOperation<O>>(
operation: O,
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
) =>
Expand All @@ -128,32 +128,37 @@ export const Thunder =
[P in keyof Z]: P extends keyof ValueTypes[R] ? Z[P] : never;
},
ops?: OperationOptions & { variables?: Record<string, unknown> },
) =>
fn(
) => {
const options = {
...thunderGraphQLOptions,
...graphqlOptions,
};
return fn(
Zeus(operation, o, {
operationOptions: ops,
scalars: graphqlOptions?.scalars,
scalars: options?.scalars,
}),
ops?.variables,
).then((data) => {
if (graphqlOptions?.scalars) {
if (options?.scalars) {
return decodeScalarsInResponse({
response: data,
initialOp: operation,
initialZeusQuery: o as VType,
returns: ReturnTypes,
scalars: graphqlOptions.scalars,
scalars: options.scalars,
ops: Ops,
});
}
return data;
}) as Promise<InputType<GraphQLTypes[R], Z, SCLR>>;
};
export const Chain = (...options: chainOptions) => Thunder(apiFetch(options));
export const SubscriptionThunder =
(fn: SubscriptionFunction) =>
<O extends keyof typeof Ops, SCLR extends ScalarDefinition, R extends keyof ValueTypes = GenericOperation<O>>(
<SCLR extends ScalarDefinition>(fn: SubscriptionFunction, thunderGraphQLOptions?: ThunderGraphQLOptions<SCLR>) =>
<O extends keyof typeof Ops, R extends keyof ValueTypes = GenericOperation<O>>(
operation: O,
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
) =>
Expand All @@ -163,24 +168,28 @@ export const SubscriptionThunder =
},
ops?: OperationOptions & { variables?: ExtractVariables<Z> },
) => {
const options = {
...thunderGraphQLOptions,
...graphqlOptions,
};
const returnedFunction = fn(
Zeus(operation, o, {
operationOptions: ops,
scalars: graphqlOptions?.scalars,
scalars: options?.scalars,
}),
) as SubscriptionToGraphQL<Z, GraphQLTypes[R], SCLR>;
if (returnedFunction?.on && graphqlOptions?.scalars) {
if (returnedFunction?.on && options?.scalars) {
const wrapped = returnedFunction.on;
returnedFunction.on = (fnToCall: (args: InputType<GraphQLTypes[R], Z, SCLR>) => void) =>
wrapped((data: InputType<GraphQLTypes[R], Z, SCLR>) => {
if (graphqlOptions?.scalars) {
if (options?.scalars) {
return fnToCall(
decodeScalarsInResponse({
response: data,
initialOp: operation,
initialZeusQuery: o as VType,
returns: ReturnTypes,
scalars: graphqlOptions.scalars,
scalars: options.scalars,
ops: Ops,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { InputType, ScalarDefinition, SelectionFunction, SubscriptionToGraphQL }
import { ExtractVariables } from '@/TreeToTS/functions/new/variableExtract';

export const Thunder =
(fn: FetchFunction) =>
<O extends keyof typeof Ops, SCLR extends ScalarDefinition, R extends keyof ValueTypes = GenericOperation<O>>(
<SCLR extends ScalarDefinition>(fn: FetchFunction, thunderGraphQLOptions?: ThunderGraphQLOptions<SCLR>) =>
<O extends keyof typeof Ops, R extends keyof ValueTypes = GenericOperation<O>>(
operation: O,
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
) =>
Expand All @@ -35,32 +35,37 @@ export const Thunder =
[P in keyof Z]: P extends keyof ValueTypes[R] ? Z[P] : never;
},
ops?: OperationOptions & { variables?: Record<string, unknown> },
) =>
fn(
) => {
const options = {
...thunderGraphQLOptions,
...graphqlOptions,
};
return fn(
Zeus(operation, o, {
operationOptions: ops,
scalars: graphqlOptions?.scalars,
scalars: options?.scalars,
}),
ops?.variables,
).then((data) => {
if (graphqlOptions?.scalars) {
if (options?.scalars) {
return decodeScalarsInResponse({
response: data,
initialOp: operation,
initialZeusQuery: o as VType,
returns: ReturnTypes,
scalars: graphqlOptions.scalars,
scalars: options.scalars,
ops: Ops,
});
}
return data;
}) as Promise<InputType<GraphQLTypes[R], Z, SCLR>>;
};

export const Chain = (...options: chainOptions) => Thunder(apiFetch(options));

export const SubscriptionThunder =
(fn: SubscriptionFunction) =>
<O extends keyof typeof Ops, SCLR extends ScalarDefinition, R extends keyof ValueTypes = GenericOperation<O>>(
<SCLR extends ScalarDefinition>(fn: SubscriptionFunction, thunderGraphQLOptions?: ThunderGraphQLOptions<SCLR>) =>
<O extends keyof typeof Ops, R extends keyof ValueTypes = GenericOperation<O>>(
operation: O,
graphqlOptions?: ThunderGraphQLOptions<SCLR>,
) =>
Expand All @@ -70,24 +75,28 @@ export const SubscriptionThunder =
},
ops?: OperationOptions & { variables?: ExtractVariables<Z> },
) => {
const options = {
...thunderGraphQLOptions,
...graphqlOptions,
};
const returnedFunction = fn(
Zeus(operation, o, {
operationOptions: ops,
scalars: graphqlOptions?.scalars,
scalars: options?.scalars,
}),
) as SubscriptionToGraphQL<Z, GraphQLTypes[R], SCLR>;
if (returnedFunction?.on && graphqlOptions?.scalars) {
if (returnedFunction?.on && options?.scalars) {
const wrapped = returnedFunction.on;
returnedFunction.on = (fnToCall: (args: InputType<GraphQLTypes[R], Z, SCLR>) => void) =>
wrapped((data: InputType<GraphQLTypes[R], Z, SCLR>) => {
if (graphqlOptions?.scalars) {
if (options?.scalars) {
return fnToCall(
decodeScalarsInResponse({
response: data,
initialOp: operation,
initialZeusQuery: o as VType,
returns: ReturnTypes,
scalars: graphqlOptions.scalars,
scalars: options.scalars,
ops: Ops,
}),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-zeus-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-zeus-core",
"version": "5.4.0",
"version": "5.4.1",
"private": false,
"main": "./lib/index.js",
"author": "GraphQL Editor, Artur Czemiel",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-zeus-jsonschema/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-zeus-jsonschema",
"version": "5.4.0",
"version": "5.4.1",
"private": false,
"main": "./lib/index.js",
"author": "GraphQL Editor, Artur Czemiel",
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql-zeus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-zeus",
"version": "5.4.0",
"version": "5.4.1",
"private": false,
"scripts": {
"start": "ttsc --watch",
Expand All @@ -26,8 +26,8 @@
"dependencies": {
"config-maker": "^0.0.2",
"cross-fetch": "^3.0.4",
"graphql-zeus-core": "^5.4.0",
"graphql-zeus-jsonschema": "^5.4.0",
"graphql-zeus-core": "^5.4.1",
"graphql-zeus-jsonschema": "^5.4.1",
"yargs": "^16.1.1"
}
}

0 comments on commit 669db69

Please sign in to comment.