Replies: 10 comments 7 replies
-
I explored a bit the codebase and slightly changed the way to support these custom types. Instead of overriding the |
Beta Was this translation helpful? Give feedback.
-
It will be handled soon with functions: const result = await chain(HOST)({},{
URL: (u) => u as string,
JSON: (u) => u as { settings: string }
}) So the scalar type will be return type of the function you provide to scalar resolvers dictionary |
Beta Was this translation helpful? Give feedback.
-
This means that this would be done at runtime, wouldn't it? |
Beta Was this translation helpful? Give feedback.
-
Yes but only once per each Scalar definition. |
Beta Was this translation helpful? Give feedback.
-
I have need for a similar thing. I'm using the
needs to become
my IDE is unhappy with me |
Beta Was this translation helpful? Give feedback.
-
Check |
Beta Was this translation helpful? Give feedback.
-
What is the recommended way to create a custom global client? I did this for Hasura to support typescript with custom scalars: import {
Chain,
GenericOperation,
GraphQLTypes,
InputType,
OperationOptions,
ScalarDefinition,
ValueTypes,
} from "./generated/zeus";
import { Ops } from "./generated/zeus/const";
export * from "./generated/zeus";
const scalars = {
jsonb: {
encode: (e: unknown) => JSON.stringify(e) as string,
decode: (e: unknown) => JSON.parse(e as string) as string,
},
JSON: {
encode: (e: unknown) => JSON.stringify(e) as string,
decode: (e: unknown) => JSON.parse(e as string) as string,
},
timestamptz: {
encode: (e: unknown) => JSON.stringify(e) as string,
decode: (e: unknown) => JSON.parse(e as string) as string,
},
};
export const ZeusClient =
(endpoint: string, secret: string) =>
<
O extends keyof typeof Ops,
R extends keyof ValueTypes = GenericOperation<O>
>(
operation: O
) => {
const chain = Chain(endpoint, {
headers: {
"x-hasura-admin-secret": secret,
},
})(operation);
return <Z extends ValueTypes[R], SCLR extends ScalarDefinition>(
o: Z | ValueTypes[R],
ops?: OperationOptions & {
scalars?: SCLR;
}
): Promise<InputType<GraphQLTypes[R], Z, SCLR & typeof scalars>> =>
chain(o as any, {
...ops,
scalars: scalars,
}) as any;
};
export type ZeusClient = ReturnType<typeof ZeusClient>;
export default ZeusClient; Seems a bit tedious, I was wondering if there is an easier way to accomplish this? |
Beta Was this translation helpful? Give feedback.
-
Of course. As I responded to the other issue. I will move scalars definition one level up as a Chain/Thunder param to make construction of those easier |
Beta Was this translation helpful? Give feedback.
-
Check [email protected] |
Beta Was this translation helpful? Give feedback.
-
forgot to publish - publishing now |
Beta Was this translation helpful? Give feedback.
-
We are using
graphql-zeus
to interact with a Hasura GraphQL server and some common types from Hasura end up being typed asany
orunknown
. For example,uuid
,timestampz
ornumeric
.Ideally, I would like to be able to extend the
typeScriptMap
used here, here and here.One approach I have in mind would be to provide a new option
--tsMappingFile
that would read a JSON file like:this custom mapping would be added to the default
typeScriptMap
I mentioned above.If you agree that this could be a nice addition, I'm ready to do a pull request for this (I would probably need a bit of guidance though).
Beta Was this translation helpful? Give feedback.
All reactions