pothos icon indicating copy to clipboard operation
pothos copied to clipboard

add withScalar method

Open Liam-Tait opened this issue 1 year ago • 10 comments

Based on this issue https://github.com/hayes/pothos/issues/910

Add method withScalars to SchemaBuilder to enable loading scalars and inferring their types for convenience. This especially helps with using existing libraries like graphql-scalars

Loading scalars is done via a method instead of as an option to enable the inference to merge the Scalars from the manually typed scalars and the inferred scalars. This is because typescript doesn't have a way to do partial inference.

Previously

const builder = new SchemaBuilder<{
  Scalars: {
    Date: {
      Input: Date;
      Output: Date;
    };
  };
}>({});

builder.addScalarType('Date', CustomDateScalar, {});

Using withScalars

const builder = new SchemaBuilder({}).withScalars({ Date: CustomDateScalar });

Liam-Tait avatar May 16 '23 13:05 Liam-Tait