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.
Uh oh!
There was an error while loading. Please reload this page.
-
We are using
graphql-zeusto interact with a Hasura GraphQL server and some common types from Hasura end up being typed asanyorunknown. For example,uuid,timestampzornumeric.Ideally, I would like to be able to extend the
typeScriptMapused here, here and here.One approach I have in mind would be to provide a new option
--tsMappingFilethat would read a JSON file like:{ "uuid": "string", "timestampz": "string", "numeric": "string" }this custom mapping would be added to the default
typeScriptMapI 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