diff --git a/examples/typescript-node/package.json b/examples/typescript-node/package.json index 0e36e24..aa36265 100644 --- a/examples/typescript-node/package.json +++ b/examples/typescript-node/package.json @@ -1,6 +1,6 @@ { "name": "typescript-node", - "version": "1.2.0", + "version": "1.2.1", "description": "", "private": true, "main": "index.js", diff --git a/packages/graphql-zeus-core/TreeToTS/functions/generated.ts b/packages/graphql-zeus-core/TreeToTS/functions/generated.ts index ed32e78..5d8bfd2 100644 --- a/packages/graphql-zeus-core/TreeToTS/functions/generated.ts +++ b/packages/graphql-zeus-core/TreeToTS/functions/generated.ts @@ -118,8 +118,8 @@ export const InternalsBuildQuery = ({ }; export const Thunder = - (fn: FetchFunction) => - >( + (fn: FetchFunction, thunderGraphQLOptions?: ThunderGraphQLOptions) => + >( operation: O, graphqlOptions?: ThunderGraphQLOptions, ) => @@ -128,32 +128,37 @@ export const Thunder = [P in keyof Z]: P extends keyof ValueTypes[R] ? Z[P] : never; }, ops?: OperationOptions & { variables?: Record }, - ) => - 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>; + }; export const Chain = (...options: chainOptions) => Thunder(apiFetch(options)); export const SubscriptionThunder = - (fn: SubscriptionFunction) => - >( + (fn: SubscriptionFunction, thunderGraphQLOptions?: ThunderGraphQLOptions) => + >( operation: O, graphqlOptions?: ThunderGraphQLOptions, ) => @@ -163,24 +168,28 @@ export const SubscriptionThunder = }, ops?: OperationOptions & { variables?: ExtractVariables }, ) => { + const options = { + ...thunderGraphQLOptions, + ...graphqlOptions, + }; const returnedFunction = fn( Zeus(operation, o, { operationOptions: ops, - scalars: graphqlOptions?.scalars, + scalars: options?.scalars, }), ) as SubscriptionToGraphQL; - if (returnedFunction?.on && graphqlOptions?.scalars) { + if (returnedFunction?.on && options?.scalars) { const wrapped = returnedFunction.on; returnedFunction.on = (fnToCall: (args: InputType) => void) => wrapped((data: InputType) => { - 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, }), ); diff --git a/packages/graphql-zeus-core/TreeToTS/functions/new/clientFunctions.ts b/packages/graphql-zeus-core/TreeToTS/functions/new/clientFunctions.ts index f05633d..9ffd0c7 100644 --- a/packages/graphql-zeus-core/TreeToTS/functions/new/clientFunctions.ts +++ b/packages/graphql-zeus-core/TreeToTS/functions/new/clientFunctions.ts @@ -25,8 +25,8 @@ import { InputType, ScalarDefinition, SelectionFunction, SubscriptionToGraphQL } import { ExtractVariables } from '@/TreeToTS/functions/new/variableExtract'; export const Thunder = - (fn: FetchFunction) => - >( + (fn: FetchFunction, thunderGraphQLOptions?: ThunderGraphQLOptions) => + >( operation: O, graphqlOptions?: ThunderGraphQLOptions, ) => @@ -35,32 +35,37 @@ export const Thunder = [P in keyof Z]: P extends keyof ValueTypes[R] ? Z[P] : never; }, ops?: OperationOptions & { variables?: Record }, - ) => - 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>; + }; export const Chain = (...options: chainOptions) => Thunder(apiFetch(options)); export const SubscriptionThunder = - (fn: SubscriptionFunction) => - >( + (fn: SubscriptionFunction, thunderGraphQLOptions?: ThunderGraphQLOptions) => + >( operation: O, graphqlOptions?: ThunderGraphQLOptions, ) => @@ -70,24 +75,28 @@ export const SubscriptionThunder = }, ops?: OperationOptions & { variables?: ExtractVariables }, ) => { + const options = { + ...thunderGraphQLOptions, + ...graphqlOptions, + }; const returnedFunction = fn( Zeus(operation, o, { operationOptions: ops, - scalars: graphqlOptions?.scalars, + scalars: options?.scalars, }), ) as SubscriptionToGraphQL; - if (returnedFunction?.on && graphqlOptions?.scalars) { + if (returnedFunction?.on && options?.scalars) { const wrapped = returnedFunction.on; returnedFunction.on = (fnToCall: (args: InputType) => void) => wrapped((data: InputType) => { - 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, }), ); diff --git a/packages/graphql-zeus-core/package.json b/packages/graphql-zeus-core/package.json index 3e93f5f..1c82c3d 100644 --- a/packages/graphql-zeus-core/package.json +++ b/packages/graphql-zeus-core/package.json @@ -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", diff --git a/packages/graphql-zeus-jsonschema/package.json b/packages/graphql-zeus-jsonschema/package.json index ae65d07..735b8df 100644 --- a/packages/graphql-zeus-jsonschema/package.json +++ b/packages/graphql-zeus-jsonschema/package.json @@ -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", diff --git a/packages/graphql-zeus/package.json b/packages/graphql-zeus/package.json index 67ad503..86ee814 100644 --- a/packages/graphql-zeus/package.json +++ b/packages/graphql-zeus/package.json @@ -1,6 +1,6 @@ { "name": "graphql-zeus", - "version": "5.4.0", + "version": "5.4.1", "private": false, "scripts": { "start": "ttsc --watch", @@ -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" } }