{"_id":"@apollo/graphql-standard-schema","_rev":"4-b01d4c610c6b0c68f716546f796cd609","name":"@apollo/graphql-standard-schema","dist-tags":{"latest":"0.2.0"},"versions":{"0.0.0":{"name":"@apollo/graphql-standard-schema","version":"0.0.0","keywords":["graphql","standard-schema","JSON schema"],"author":{"name":"packages@apollographql.com"},"license":"MIT","_id":"@apollo/graphql-standard-schema@0.0.0","maintainers":[{"name":"hwillson","email":"hugh@octonary.com"},{"name":"abernix","email":"npmjs@jro.cc"},{"name":"andrewmcgivery","email":"andrew.mcgivery@apollographql.com"},{"name":"gocamille","email":"camille.lawrence@gmail.com"},{"name":"phryneas","email":"mail@lenzw.de"}],"dist":{"shasum":"437e1461ad7e8e58eece0ee77ac7b37d67ed921d","tarball":"https://registry.npmjs.org/@apollo/graphql-standard-schema/-/graphql-standard-schema-0.0.0.tgz","fileCount":1,"integrity":"sha512-xOiAOWJWrII8RLUIQryPDv4DVokdfCjqPRV7fb4q9RqBdeABfrgEQoWCzsOSMBKOSZjzEUIl9DZxWc3xQtG1pQ==","signatures":[{"sig":"MEUCIQDrImcK6gvhKq1zHRI1rdbibm2U3YA4AGctoo+9WIh9WAIgAtEBEAREMSCMg8dEXsPL6Qjg8f6ag2HxBQBFDstzlKI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":292},"gitHead":"8eb922a94cabd871d8afb751cb56a822a29f678b","_npmUser":{"name":"phryneas","email":"mail@lenzw.de"},"repository":{"url":"git+https://github.com/graphql-standard-schema"},"_npmVersion":"11.1.0","directories":{},"_nodeVersion":"23.9.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/graphql-standard-schema_0.0.0_1765361735250_0.054010641372449264","host":"s3://npm-registry-packages-npm-production"}},"0.1.0":{"name":"@apollo/graphql-standard-schema","version":"0.1.0","keywords":["graphql","standard-schema","JSON schema"],"author":{"name":"packages@apollographql.com"},"license":"MIT","_id":"@apollo/graphql-standard-schema@0.1.0","maintainers":[{"name":"hwillson","email":"hugh@octonary.com"},{"name":"abernix","email":"npmjs@jro.cc"},{"name":"andrewmcgivery","email":"andrew.mcgivery@apollographql.com"},{"name":"gocamille","email":"camille.lawrence@gmail.com"},{"name":"phryneas","email":"mail@lenzw.de"}],"homepage":"https://github.com/apollographql/graphql-standard-schema#readme","bugs":{"url":"https://github.com/apollographql/graphql-standard-schema/issues"},"dist":{"shasum":"1891bbeab75fd75697e752bbdde737e95c1658eb","tarball":"https://registry.npmjs.org/@apollo/graphql-standard-schema/-/graphql-standard-schema-0.1.0.tgz","fileCount":103,"integrity":"sha512-uYNLHG2NAhixi82RQlP2llKsFlSOjns9usSDAg9OAiMU7J9oCBISrhNcrdPssjEahKQhUpKwZF2PyE+Fe8HSmA==","signatures":[{"sig":"MEUCIFpRybdq3aq3RXwEJydIQlJ9KhCP3BXbkse7eQJuNca3AiEAqFaLaFbZ+DjatJUlCR1D5BRb9DgP5F/t5mY1EyCvwd0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@apollo%2fgraphql-standard-schema@0.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":196647},"type":"module","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"gitHead":"00e34ba276ba679a8c702fb504258920354afb20","scripts":{"lint":"oxlint --type-aware -c oxlintrc.json src test","test":"node --disable-warning=ExperimentalWarning --experimental-test-coverage --test","build":"tsc","clean":"node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"","prepack":"npm run clean && npm run build","release":"changeset publish","version":"changeset version","changeset":"changeset"},"typings":"./dist/index.d.ts","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:854e2eaa-6346-42f3-861a-95ecd5f06002"}},"repository":{"url":"git+https://github.com/apollographql/graphql-standard-schema.git"},"_npmVersion":"11.6.2","description":"This package allows you to create [Standard Schema](https://github.com/standard-schema/standard-schema) compliant Schemas for GraphQL operation responses, data, fragments or input variables.","directories":{},"sideEffects":false,"_nodeVersion":"24.11.1","dependencies":{"@standard-schema/spec":"^1.0.0","@graphql-typed-document-node/core":"^3.2.0"},"_hasShrinkwrap":false,"devDependencies":{"ajv":"^8.17.1","zod":"^4.1.12","oxlint":"^1.32.0","graphql":"^16.12.0","prettier":"^3.6.2","typescript":"^5.9.2","@types/node":"^24.3.1","expect-type":"^1.2.2","@wry/equality":"^0.5.7","@changesets/cli":"^2.29.8","fast-json-patch":"^3.1.1","graphql-scalars":"^1.25.0","oxlint-tsgolint":"^0.8.4"},"peerDependencies":{"zod":"^3 || ^4","graphql":"^16 || ^17.0.0-alpha"},"peerDependenciesMeta":{"zod":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/graphql-standard-schema_0.1.0_1765380881295_0.4936009118903375","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@apollo/graphql-standard-schema","version":"0.2.0","keywords":["graphql","standard-schema","JSON schema","StandardSchemaV1","StandardJSONSchemaV1"],"author":{"name":"packages@apollographql.com"},"license":"MIT","_id":"@apollo/graphql-standard-schema@0.2.0","maintainers":[{"name":"hwillson","email":"hugh@octonary.com"},{"name":"abernix","email":"npmjs@jro.cc"},{"name":"andrewmcgivery","email":"andrew.mcgivery@apollographql.com"},{"name":"gocamille","email":"camille.lawrence@gmail.com"},{"name":"phryneas","email":"mail@lenzw.de"}],"homepage":"https://github.com/apollographql/graphql-standard-schema#readme","bugs":{"url":"https://github.com/apollographql/graphql-standard-schema/issues"},"dist":{"shasum":"d7e7e26191914a0fd18f6194da5aa5129c6486bf","tarball":"https://registry.npmjs.org/@apollo/graphql-standard-schema/-/graphql-standard-schema-0.2.0.tgz","fileCount":95,"integrity":"sha512-HUr/aoPVRNtkLzOkgwbUylSz2BHrTtVz79beY21n1Pd9qjK7p1JjwIsgNg/oEpKpM5FhHx+iIOyoecA719UuYg==","signatures":[{"sig":"MEYCIQDgdPNl3Q4X7dHgXdSR8BECODfgb5SpKTNcYaqBgVlB1gIhAIuK8dbZWwXQljy9GLczSn//KwBjWCSDltDCOVKTeCg2","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@apollo%2fgraphql-standard-schema@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":186086},"type":"module","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"gitHead":"4c48c56c006dbc1e9a49e1d3b13e4398325c7b74","scripts":{"lint":"oxlint --type-aware -c oxlintrc.json src test","test":"node --disable-warning=ExperimentalWarning --experimental-test-coverage --test","build":"tsc","clean":"node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"","prepack":"npm run clean && npm run build","release":"changeset publish","version":"changeset version","changeset":"changeset"},"typings":"./dist/index.d.ts","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:854e2eaa-6346-42f3-861a-95ecd5f06002"}},"repository":{"url":"git+https://github.com/apollographql/graphql-standard-schema.git"},"_npmVersion":"11.6.2","description":"This package allows you to create [Standard Schema](https://github.com/standard-schema/standard-schema) (both `StandardSchemaV1` and `StandardJSONSchemaV1`) compliant Schemas for GraphQL data, fragments, operation responses or input variables.","directories":{},"sideEffects":false,"_nodeVersion":"24.11.1","dependencies":{"@standard-schema/spec":"^1.1.0","@graphql-typed-document-node/core":"^3.2.0"},"_hasShrinkwrap":false,"devDependencies":{"ajv":"^8.17.1","zod":"^4.2.1","oxlint":"^1.32.0","graphql":"^16.12.0","prettier":"^3.6.2","typescript":"^5.9.2","@types/node":"^24.3.1","expect-type":"^1.2.2","@wry/equality":"^0.5.7","@changesets/cli":"^2.29.8","fast-json-patch":"^3.1.1","graphql-scalars":"^1.25.0","oxlint-tsgolint":"^0.8.4"},"peerDependencies":{"zod":"^3 || ^4","graphql":"^16 || ^17.0.0-alpha"},"peerDependenciesMeta":{"zod":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/graphql-standard-schema_0.2.0_1765963604518_0.7047135146270453","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-12-10T10:15:35.172Z","modified":"2026-04-07T17:18:36.754Z","0.0.0":"2025-12-10T10:15:35.387Z","0.1.0":"2025-12-10T15:34:41.432Z","0.2.0":"2025-12-17T09:26:45.031Z"},"bugs":{"url":"https://github.com/apollographql/graphql-standard-schema/issues"},"author":{"name":"packages@apollographql.com"},"license":"MIT","homepage":"https://github.com/apollographql/graphql-standard-schema#readme","keywords":["graphql","standard-schema","JSON schema","StandardSchemaV1","StandardJSONSchemaV1"],"repository":{"url":"git+https://github.com/apollographql/graphql-standard-schema.git"},"description":"This package allows you to create [Standard Schema](https://github.com/standard-schema/standard-schema) (both `StandardSchemaV1` and `StandardJSONSchemaV1`) compliant Schemas for GraphQL data, fragments, operation responses or input variables.","maintainers":[{"email":"hugh@octonary.com","name":"hwillson"},{"email":"npmjs@jro.cc","name":"abernix"},{"email":"isaac.m.good@apollographql.com","name":"imgood-apollo"},{"email":"andrew.mcgivery@apollographql.com","name":"andrewmcgivery"},{"email":"camille.lawrence@gmail.com","name":"gocamille"},{"email":"mail@lenzw.de","name":"phryneas"}],"readme":"This package allows you to create [Standard Schema](https://github.com/standard-schema/standard-schema) (both `StandardSchemaV1` and `StandardJSONSchemaV1`) compliant Schemas for GraphQL data, fragments, operation responses or input variables.\n\n## Creating a Schema Generator\n\n```ts\nimport { GraphQLStandardSchemaGenerator } from \"@apollo/graphql-standard-schema\";\n\nconst generator = new GraphQLStandardSchemaGenerator({\n  schema: gql`\n    type Query {\n      hello: String\n    }\n  `,\n});\n// or\nconst generator = new GraphQLStandardSchemaGenerator({\n  schema: new GraphQLSchema({ ... } ),\n});\n```\n\n### Specifying custom Scalar types\n\nYou can also specify custom Scalar type definitions to control how those types are validated and how they end up in potentially generated JSON schemas:\n\n```ts\nconst generator = new GraphQLStandardSchemaGenerator({\n  schema: gql`\n    scalar Date\n    type Query {\n      now: Date!\n    }\n  `,\n  scalarTypes: {\n    Date: new GraphQLScalarType<number, string>({\n      name: \"Date\",\n      description: \"A date string in YYYY-MM-DD format\",\n      parseValue(value) {\n        const date = new Date(value as string);\n        if (isNaN(date.getTime())) {\n          throw new TypeError(\n            `Value is not a valid Date string: ${value as string}`\n          );\n        }\n        return date.getTime();\n      },\n      serialize(value) {\n        if (typeof value === \"number\") {\n          value = new Date(value);\n        }\n        if (!(value instanceof Date) || isNaN(value.getTime())) {\n          throw new TypeError(`Value is not a valid Date object: ${value}`);\n        }\n        return value.toISOString().split(\"T\")[0];\n      },\n      extensions: {\n        \"@apollo/graphql-standard-schema\": {\n          serializedJsonSchema: {\n            type: \"string\",\n            pattern: \"\\\\d{4}-\\\\d{1,2}-\\\\d{1,2}\",\n          },\n          deserializedJsonSchema: {\n            type: \"number\",\n            // description will usually be inherited from the GraphQLScalarType description, but in this case we override it to match with the actual deserialized value\n            description: \"Unix timestamp in milliseconds\",\n          },\n        },\n      },\n    }),\n  },\n});\n```\n\n> [!TIP]\n> The JSON schema definitions are stored in the `extensions` field of the `GraphQLScalarType` under the key `\"@apollo/graphql-standard-schema\"`. This allows the scalar type to be used as a normal GraphQL scalar while also providing the necessary JSON schema information for validation and schema generation.\n\n### All options:\n\n```ts\nnamespace GraphQLStandardSchemaGenerator {\n  export interface Options {\n    schema: GraphQLSchema | DocumentNode;\n    scalarTypes?: Scalars;\n    defaultJSONSchemaOptions?: JSONSchemaOptions | \"OpenAI\";\n    /**\n     * An array of document transforms to apply to each document before generating schemas.\n     *\n     * This can be used to apply custom transformations to the GraphQL documents,\n     * such as adding default fields, removing deprecated fields, etc.\n     *\n     * Defaults to `[addTypename]` if not provided.\n     */\n    documentTransfoms?: GraphQLStandardSchemaGenerator.DocumentTransform[];\n  }\n\n  export interface JSONSchemaOptions {\n    /**\n     * If true, nullable properties will be marked as optional in the generated JSON Schema.\n     *\n     * {@defaultValue true}\n     *\n     * When `defaultJSONSchemaOptions` is set to \"OpenAI\", this will be false.\n     */\n    optionalNullableProperties?: boolean;\n    /**\n     * If set to either `true` or `false`, this setting will be added to all object types.\n     * @defaultValue undefined\n     *\n     * When `defaultJSONSchemaOptions` is set to \"OpenAI\", this will be false.\n     */\n    additionalProperties?: boolean;\n  }\n}\n```\n\n> [!NOTE]\n> For more information on `defaultJSONSchemaOptions`, see [Standard JSON Schema and JSON Schema generation](#standard-json-schema-and-json-schema-generation).\n\n## Schemas\n\nCurrently, this package supports generating the following types of schemas:\n\n- Response schema - validates the entire GraphQL operation result (either `data` or `errors` field)\n- Data schema - validates only the `data` field of a GraphQL operation result\n- Fragment schema - validates the value of a GraphQL fragment\n- Variables schema - validates the input variables for a GraphQL operation\n\n### Validating GraphQL results\n\n```ts\n// create a \"response\" schema that will validate the result of a GraphQL operation\nconst responseSchema = generator.getResponseSchema(gql`\n  query GetHello {\n    hello\n  }\n`);\n\n// this schema can now be used to validate GraphQL operation results\n// results are either { valid: validInput } or { issues: [...] }\nconst result = responseSchema({\n  data: {\n    hello: \"world\",\n  },\n});\n// result: is { value: { data: { hello: 'world' } } }\n\n// this is also a valid GraphQL operation result - an object containing `errors` instead of `data`.\nconst result = responseSchema({\n  errors: [{ message: \"Something went wrong\" }],\n});\n// result: is { value: { errors: [ { message: \"Something went wrong\" } ] } }\n\n// this is an incorrect response\nconst result = responseSchema({\n  data: {\n    hello: 1,\n  },\n});\n/*\n// result is\n{\n  issues: [\n    {\n      message: 'String cannot represent a non string value: 1',\n      path: [ 'data', 'hello' ]\n    }\n  ]\n}\n*/\n```\n\n> [!NOTE]\n> `getResponseSchema` returns a multidirectional schema - see [directional schemas](#directional-schemas) for more details.\n\n### Validating GraphQL data\n\nYou can also create a \"data schema\" that will validate the `data` field of a GraphQL operation result:\n\n```ts\nconst dataSchema = generator.getDataSchema(gql`\n  query GetHello {\n    hello\n  }\n`);\n\nconst result = dataSchema({\n  hello: \"world\",\n});\n// result is now { value: { hello: 'world' } }\n\n// invalid data\nconst result = dataSchema({\n  hello: { completely: \"wrong\" },\n});\n/*\n// result is\n{\n  issues: [\n    {\n      message: 'String cannot represent a non string value: { completely: \"wrong\" }',\n      path: [ 'hello' ]\n    }\n  ]\n}\n*/\n```\n\n> [!NOTE]\n> `getDataSchema` returns a multidirectional schema - see [directional schemas](#directional-schemas) for more details.\n\n### Validating GraphQL fragments\n\nYou can also create a schema to validate a fragment value:\n\n```ts\nconst generator = new GraphQLStandardSchemaGenerator({\n  schema: gql(`\n    type User {\n      id: ID!\n      name: String!\n      email: String!\n    }\n\n    type Query {\n      me: User\n    }\n  `),\n});\n\nconst fragmentSchema = generator.getFragmentSchema(\n  gql(`\n  fragment UserDetails on User {\n    id\n    name\n    email\n  }\n`)\n);\n\n// valid\nconst result = fragmentSchema({\n  // value now needs to contain `__typename` to match the fragment type condition\n  __typename: \"User\",\n  id: 123,\n  name: \"Alice\",\n  email: \"alice@example.com\",\n});\n/*\n// result is\n{\n  value: {\n    __typename: 'User',\n    id: '123',\n    name: 'Alice',\n    email: 'alice@example.com'\n  }\n}\n*/\n```\n\nWhen you have multiple fragments, specify which one to use\n\n```ts\nconst multiFragmentSchema = generator.getFragmentSchema(\n  gql`\n    fragment UserBasic on User {\n      id\n      name\n    }\n\n    fragment UserFull on User {\n      id\n      name\n      email\n    }\n  `,\n  { fragmentName: \"UserFull\" }\n);\n\n// valid - validates against the UserFull fragment\nconst result = multiFragmentSchema({\n  __typename: \"User\",\n  id: 123,\n  name: \"Alice\",\n  email: \"alice@example.com\",\n});\n/*\n// result is\n{\n  value: {\n    __typename: 'User',\n    id: '123',\n    name: 'Alice',\n    email: 'alice@example.com'\n  }\n}\n*/\n```\n\n> [!NOTE]\n> `getFragmentSchema` returns a multidirectional schema - see [directional schemas](#directional-schemas) for more details.\n\n### Validating GraphQL variables\n\n`generator.getVariablesSchema` allows you to create a schema that validates the input variables for a GraphQL operation:\n\n```ts\nconst generator = new GraphQLStandardSchemaGenerator({\n  schema: gql`\n    scalar Date\n    input EventSearchInput {\n      after: Date\n      before: Date\n      city: String!\n    }\n    type Query {\n      searchEvent(input: EventSearchInput!): [String]\n    }\n  `,\n  scalarTypes: {\n    Date: DateScalarDef,\n  },\n});\n\nconst variablesSchema = generator.getVariablesSchema(gql`\n  query Search($input: EventSearchInput!) {\n    searchEvent(input: $input)\n  }\n`);\n\n// valid input\nconst result = variablesSchema({\n  input: {\n    after: \"2025-01-01\",\n    city: \"New York\",\n  },\n});\n// result is `{ value: { input: { after: '2025-01-01', city: 'New York' } } }`\n\n// invalid input\nconst result = variablesSchema({\n  input: {\n    after: \"2025-01-01\",\n    before: \"2025-12-31\",\n  },\n});\n/*\n// result is\n{\n  \"issues\": [\n    {\n      \"message\": \"Expected value to be non-null.\",\n      \"path\": [\n        \"input\",\n        \"city\"\n      ]\n    }\n  ]\n}\n*/\n```\n\n> [!NOTE]\n> `getVariablesSchema` returns a multidirectional schema - see [directional schemas](#directional-schemas) for more details.\n\n> [!INFO]\n> `getVariablesSchema` will not add `null` for missing nullable fields by default, unless they were part of the input.\n> Variable inputs can be very deeply nested with a lot of unspecified fields, so adding them indiscriminately could lead to very large objects.\n\n### Directional Schemas\n\nThe moment you add scalars with custom serialization or parsing/deserialization logic, your schemas become \"directional\" - meaning they can validate data in multiple \"directions\":\n\n- `schema.normalize` is a function (and full StandardSchema schema) that validates serialized data. It takes serialized data as input, and outputs serialized data. This is the normal behaviour for all multidirectional schemas.\n- `schema.deserialize` is a function (and full StandardSchema schema) that validates deserialized data. It takes deserialized data as input, and outputs deserialized data.\n- `schema.serialize` is a function (and full StandardSchema schema) that validates serialized data. It takes serialized data as input, and outputs serialized data.\n\nSo for example for this schema:\n\n```ts\nconst generator = new GraphQLStandardSchemaGenerator({\n  schema: gql`\n    scalar Date\n    type Query {\n      now: Date!\n      holidayName: String\n    }\n  `,\n  scalarTypes: {\n    Date: new GraphQLScalarType<number, string>({\n      name: \"Date\",\n      // serialization and deserialization logic\n      parseValue(value) {\n        /* ... */\n      },\n      serialize(value) {\n        /* ... */\n      },\n      extensions: {\n        \"@apollo/graphql-standard-schema\": {\n          serializedJsonSchema: {\n            type: \"string\",\n            pattern: \"\\\\d{4}-\\\\d{1,2}-\\\\d{1,2}\",\n          },\n          deserializedJsonSchema: {\n            type: \"number\",\n            description: \"Unix timestamp in milliseconds\",\n          },\n        },\n      },\n    }),\n  },\n});\n\nconst dataSchema = generator.getDataSchema(gql`\n  query GetNow {\n    now\n    holidayName\n  }\n`);\n```\n\nLet's look at some different behaviors:\n\n#### `normalize` examples\n\n```ts\nconst result = dataSchema.normalize({\n  now: \"2025-12-31\",\n  holidayName: \"New Year's Eve\",\n});\n// result is `{ value: { now: '2025-12-31', holidayName: \"New Year's Eve\" } }`\n```\n\n> [!NOTE]\n> `normalize` is the default behavior for multidirectional schemas, so calling `dataSchema(data)` is equivalent to calling `dataSchema.normalize(data)`.\n\n`normalize` will also try to fix data that is in the wrong format to bring it into the correct serialized format:\n\n```ts\nconst result = dataSchema.normalize({\n  now: \"Dec 13, 2025\",\n});\n// result is `{ value: { now: '2025-12-12', holidayName: null } }`\n```\n\nTwo observations here:\n\n- The input date string \"Dec 13, 2025\" was successfully parsed and reformatted to the correct \"YYYY-MM-DD\" format by passing it through the `parseValue` and `serialize` methods of the `Date` scalar.\n- The missing `holidayName` field was automatically set to `null`, as per GraphQL's default behavior for nullable fields.\n\n#### `deserialize` examples\n\n```ts\nconst result = dataSchema.deserialize({\n  now: \"2025-12-31\",\n  holidayName: \"New Year's Eve\",\n});\n// result is `{ value: { now: 1767139200000, holidayName: \"New Year's Eve\" } }`\n```\n\n```ts\nconst result = dataSchema.deserialize({\n  now: \"Dec 13, 2025\",\n});\n// result is `{ value: { now: 1765580400000, holidayName: null } }`\n```\n\n#### `serialize` examples\n\n```ts\nconst result = dataSchema.serialize({\n  now: 1767139200000,\n  holidayName: \"New Year's Eve\",\n});\n// result is `{ value: { now: '2025-12-31', holidayName: \"New Year's Eve\" } }`\n```\n\n```ts\nconst result = dataSchema.serialize({\n  now: new Date(\"Dec 13, 2025\"),\n});\n// result is `{ value: { now: '2025-12-13', holidayName: null } }`\n```\n\n### Usage with TypeScript\n\nIf you pass `TypedDocumentNode` instances to the schema generator methods, the returned schemas will be fully typed according to the GraphQL operation types.\n\n```ts\nconst generator = new GraphQLStandardSchemaGenerator({\n  schema: gql`\n    scalar Date\n    type Query {\n      now: Date!\n      where: String!\n    }\n  `,\n  scalarTypes: {\n    Date: new GraphQLScalarType<Date, string>({\n      /* ... */\n    }),\n  },\n});\n\nconst query: TypedDocumentNode<{ now: Date; where: string }, {}> = gql`\n  query GetNow {\n    now\n    where\n  }\n`;\n\nconst schema = generator.getDataSchema(query);\nconst normalizedResult = schema(unknownValue);\n//     ^? StandardSchemaV1.Result<{ now: string; where: string; }>\n\nconst serializedResult = schema.serialize(unknownValue);\n//     ^? StandardSchemaV1.Result<{ now: string; where: string; }>\n\nconst deserializedResult = schema.deserialize(unknownValue);\n//     ^? StandardSchemaV1.Result<{ now: Date; where: string; }>\n```\n\nYou can use the `StandardSchemaV1.InferInput` and `StandardSchemaV1.InferOutput` utility types to infer the input and output types of the generated schemas.\n\n```ts\ntype Serialized = StandardSchemaV1.InferInput<typeof schema.deserialize>;\n//    ^? { now: string; where: string; }\ntype Deserialized = StandardSchemaV1.InferOutput<typeof schema.deserialize>;\n//    ^? { now: Date; where: string; }\n```\n\n## Standard Schema Integration\n\nEvery schema generated by this package is fully compliant with the [Standard Schema](https://standardschema.dev/) interface and can be used anywhere a Standard Schema is expected.\n\nSo you could use a `validateInput` function like this one to validate input data against a schema generated by this package:\n\n```ts\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nfunction validateInput(schema: StandardSchemaV1, data: unknown) {\n  const result = schema[\"~standard\"].validate(data);\n  if (result instanceof Promise) {\n    throw new TypeError(\"Schema validation must be synchronous\");\n  }\n  if (result.issues) {\n    throw new Error(JSON.stringify(result.issues, null, 2));\n  }\n\n  return result.value;\n}\n```\n\n## Standard JSON Schema and JSON Schema generation\n\nThis package implements `StandardJSONSchemaV1` for all generated schemas, so you can use them in all libraries that support Standard JSON Schema. (E.g. the [ai SDK](https://www.npmjs.com/package/ai), [TanStack AI](https://www.npmjs.com/package/@tanstack/ai), among many others)\n\n### Options for JSON Schema generation\n\nWhen creating a `GraphQLStandardSchemaGenerator`, you can specify options that will control how JSON Schemas are generated from the GraphQL schema by passing in a configuration in the `defaultJSONSchemaOptions`.\n\nYou can also pass in these values into the `toJSONSchema` functions to override the defaults set in the generator:\n\n```ts\ntoJSONSchema.input(dataSchema, {\n  optionalNullableProperties: false,\n});\n```\n\nThe available options are:\n\n```ts\nnamespace GraphQLStandardSchemaGenerator {\n  export interface JSONSchemaOptions {\n    /**\n     * If true, nullable properties will be marked as optional in the generated JSON Schema.\n     *\n     * {@defaultValue true}\n     *\n     * When `defaultJSONSchemaOptions` is set to \"OpenAI\", this will be false.\n     */\n    optionalNullableProperties?: boolean;\n    /**\n     * If set to either `true` or `false`, this setting will be added to all object types.\n     * @defaultValue undefined\n     *\n     * When `defaultJSONSchemaOptions` is set to \"OpenAI\", this will be false.\n     */\n    additionalProperties?: boolean;\n  }\n}\n```\n\n### Usage with OpenAI object generation\n\nWhile OpenAI object generation works with JSON Schema, it doesn't follow a specific version of the standard and has some specific requirements around how schemas should be structured.\nTo get JSON Schemas that are optimized for OpenAI object generation, you can set the `defaultJSONSchemaOptions` to `\"OpenAI\"` when creating the `GraphQLStandardSchemaGenerator`.\n\n```ts\nconst generator = new GraphQLStandardSchemaGenerator({\n  schema: gql`\n    type Query {\n      hello: String\n    }\n  `,\n  defaultJSONSchemaOptions: \"OpenAI\",\n});\n```\n\n## Other exports\n\nIn addition to the `GraphQLStandardSchemaGenerator`, this package also exports some utility functions:\n\n### toJSONSchema\n\nConverts any schema generated with `GraphQLStandardSchemaGenerator` as well as any other `StandardJSONSchemaV1` to JSON Schema\n\n#### Signature:\n\n```ts\nconst toJSONSchema: {\n  input(\n    standardSchema: StandardJSONSchemaV1<unknown, unknown>,\n    options?: StandardJSONSchemaV1.Options & {\n      libraryOptions?: GraphQLStandardSchemaGenerator.JSONSchemaOptions;\n    }\n  ): Record<string, unknown>;\n  output(\n    standardSchema: StandardJSONSchemaV1<unknown, unknown>,\n    options?: StandardJSONSchemaV1.Options & {\n      libraryOptions: GraphQLStandardSchemaGenerator.JSONSchemaOptions;\n    }\n  ): Record<string, unknown>;\n};\n```\n\nIf no options are provided, they default to `{ target: \"draft-2020-12\" }`n\n\n#### Usage:\n\n```ts\nconst responseSchema = generator.getResponseSchema(gql`\n  query GetHello {\n    hello\n  }\n`);\nconst jsonSchema = toJSONSchema.input(responseSchema.serialized, {\n  target: \"draft-2020-12\",\n  libraryOptions: {\n    optionalNullableProperties: false,\n  },\n});\n```\n\n### `composeStandardSchemas`\n\nComposes multiple `StandardJSONSchemaV1` schemas into a single schema.\n\n> [!NOTE]\n> This library is somewhat limited and might not account for `anyOf` etc. in the root schema.\n\n#### Signature:\n\n```ts\n// `CombinedSpec` is a combination of `StandardSchemaV1` and `StandardJSONSchemaV1`\n\nfunction composeStandardSchemas<\n  Root extends CombinedSpec<any, any>,\n  const Path extends string[],\n  Extension extends CombinedSpec<any, any>,\n  Required extends boolean = true,\n>(\n  /** The root schema. */\n  rootSchema: Root,\n  /** The path at which the extension schema should be included in the combined schema. */\n  path: Path,\n  /** The extension/child schema. */\n  extension: Extension,\n  /** If the child schema should be considered a required prop in the combined schema */\n  required: Required = true as Required,\n  /** If the property at `path` should be hidden from runtime checks when validating the root schema part */\n  hideAddedFieldFromRootSchema = true\n): CombinedSpec<\n  InsertAt<\n    StandardSchemaV1.InferInput<Root>,\n    P,\n    StandardSchemaV1.InferInput<Extension>,\n    Required\n  >,\n  InsertAt<\n    StandardSchemaV1.InferOutput<Root>,\n    P,\n    StandardSchemaV1.InferOutput<Extension>,\n    Required\n  >\n>;\n```\n\n#### Usage:\n\n```ts\nconst combinedStandardJSONSchema = composeStandardSchemas(\n  z.strictObject({\n    props: z.strictObject({\n      id: z.string().uuid(),\n      name: z.string(),\n    }),\n  }),\n  [\"props\", \"data\"],\n  schema\n);\nconst jsonSchema = toJSONSchema.input(combinedStandardJSONSchema);\n```\n\n### `addTypename`\n\nA document transform that adds `__typename` fields to all selection sets in a GraphQL document. This is the default document transform applied by `GraphQLStandardSchemaGenerator`, you might need to reference this if you want to apply it alongside your own custom document transforms.\n\n#### Usage:\n\n```ts\nconst generator = new GraphQLStandardSchemaGenerator({\n  schema: gql`... `,\n  documentTransfoms: [addTypename, myCustomTransform],\n});\n```\n","readmeFilename":"README.md"}