Skip to content

Scalars not used for decoding in Apollo hooks #419

@dspasojevic

Description

@dspasojevic

When using Chain directly, the decodeScalarsInResponse function is called by Thunder / ThunderDescription so that scalars are applied to the response, aligning the actual values with the types expressed by InputType<GraphQLTypes[R], Z, UnionOverrideKeys<SCLR, OVERRIDESCLR>>. That is, so that the values are decoded and match the expected types.

This aligns with the documentation examples:

const listCardsAndDraw = await chain('query', {
  scalars: {
    JSON: {
      encode: (e: unknown) => JSON.stringify(e),
      decode: (e: unknown) => JSON.parse(e as string),
    },
    Datetime: {
      decode: (e: unknown) => new Date(e as string),
      encode: (e: unknown) => (e as Date).toISOString(),
    },
  },
})({
  drawCard: {
    info: true,
  },
});

that implies that the (eg) DateTime scalar's decode function to have been called.

The same is not true when using useTypedQuery. The scalar decoder functions are not run. However, the types imply that they are. This means that the actual values may not align with the types.

Should the decoders be run when using useTypedQuery?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions