Skip to content

Instantly share code, notes, and snippets.

@cristianoc
Forked from zth/bun-headers.md
Created November 1, 2023 13:57
Show Gist options
  • Save cristianoc/d556de8581fad3a53a67294b67f495c5 to your computer and use it in GitHub Desktop.
Save cristianoc/d556de8581fad3a53a67294b67f495c5 to your computer and use it in GitHub Desktop.
TS -> ReScript examples

TypeScript:

export type YogaServerOptions<TServerContext, TUserContext> = {
  schema?: YogaSchemaDefinition<TServerContext, TUserContext> | undefined;
 
  /**
   * Enable/disable logging or provide a custom logger.
   * @default true
   */
  logging?: boolean | YogaLogger | LogLevel | undefined;
  /**
   * Prevent leaking unexpected errors to the client. We highly recommend enabling this in production.
   * If you throw `EnvelopError`/`GraphQLError` within your GraphQL resolvers then that error will be sent back to the client.
   *
   * You can lean more about this here:
   * @see https://graphql-yoga.vercel.app/docs/features/error-masking
   *
   * @default true
   */
  maskedErrors?: boolean | Partial<YogaMaskedErrorOpts> | undefined;

  /**
   * GraphQL endpoint
   * So you need to define it explicitly if GraphQL API lives in a different path other than `/graphql`
   *
   * @default "/graphql"
   */
  graphqlEndpoint?: string | undefined;

  /**
   * Readiness check endpoint
   *
   * @default "/health"
   */
  healthCheckEndpoint?: string | undefined;

  /**
   * Whether the landing page should be shown.
   */
  landingPage?: boolean | undefined;

  /**
   * GraphiQL options
   *
   * @default true
   */
  graphiql?: GraphiQLOptionsOrFactory<TServerContext> | undefined;

  /**
   * GraphQL Multipart Request spec support
   *
   * @see https://github.com/jaydenseric/graphql-multipart-request-spec
   *
   * @default true
   */
  multipart?: boolean | undefined;
  id?: string | undefined;
  /**
   * Batching RFC Support configuration
   *
   * @see https://github.com/graphql/graphql-over-http/blob/main/rfcs/Batching.md
   *
   * @default false
   */
  batching?: BatchingOptions | undefined;
};

ReScript:

type logFn = unknown => unit
type yogaLogger = {debug: logFn, info: logFn, warn: logFn, error: logFn}

@unboxed
type logging =
  | @as(true) True
  | @as(false) False
  | YogaLogger(yogaLogger)
  | @as("debug") LogLevelDebug
  | @as("info") LogLevelInfo
  | @as("warn") LogLevelWarn
  | @as("error") LogLevelError
  
type batchingOptions = {
  /**
   * You can limit the number of batched operations per request.
   *
   * @default 10
   */
  limit?: int,
}

@unboxed type batchingConfig = | @as(true) True | @as(false) False | Options(batchingOptions)

/**
 * Configuration options for the server
 */
type yogaServerOptions<'tServerContext, 'tUserContext> = {
  schema: YogaSchemaDefinition.t<'tServerContext, 'tUserContext>,
  /**
   * Enable/disable logging or provide a custom logger.
   * @default true
   */
  logging?: logging,
  /**
   * Prevent leaking unexpected errors to the client. We highly recommend enabling this in production.
   * If you throw `EnvelopError`/`GraphQLError` within your GraphQL resolvers then that error will be sent back to the client.
   *
   * You can lean more about this here:
   * @see https://graphql-yoga.vercel.app/docs/features/error-masking
   *
   * @default true
   */
  maskedErrors?: maskedErrors,
  /**
   * GraphQL endpoint
   * So you need to define it explicitly if GraphQL API lives in a different path other than `/graphql`
   *
   * @default "/graphql"
   */
  graphqlEndpoint?: string,
  /**
   * Readiness check endpoint
   *
   * @default "/health"
   */
  healthCheckEndpoint?: string,
  /**
   * Whether the landing page should be shown.
   */
  landingPage?: bool,
  parserCache?: bool,
  validationCache?: bool,
  /**
   * GraphQL Multipart Request spec support
   *
   * @see https://github.com/jaydenseric/graphql-multipart-request-spec
   *
   * @default true
   */
  multipart?: bool,
  id?: string,
  /**
   * Batching RFC Support configuration
   *
   * @see https://github.com/graphql/graphql-over-http/blob/main/rfcs/Batching.md
   *
   * @default false
   */
  batching?: batchingConfig,
  /**
   * Whether to use the legacy Yoga Server-Sent Events and not
   * the GraphQL over SSE spec's distinct connection mode.
   *
   * @default true
   *
   * @deprecated Consider using GraphQL over SSE spec instead by setting this to `false`. Starting with the next major release, this flag will default to `false`.
   */
  legacySse?: bool,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment