PageSourceSearch

https://build.graphile.org/assets/js/62a8072a.ba57a0f9.js

js graphile.org collected 2026-10-02 07:05:53 UTC 25,821 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunk_localrepo_graphile_build_website=globalThis.webpackChunk_localrepo_graphile_build_website||[]).push([[1852],{2281(e,n,i){i.r(n),i.d(n,{assets:()=>c,contentTitle:()=>d,default:()=>u,frontMatter:()=>o,metadata:()=>t,toc:()=>p});const t=JSON.parse('{"id":"all-hooks","title":"All Hooks","description":"Registering a schema hook","source":"@site/versioned_docs/version-5/all-hooks.mdx","sourceDirName":".","slug":"/all-hooks","permalink":"/graphile-build/5/all-hooks","draft":false,"unlisted":false,"editUrl":"https://github.com/graphile/crystal/tree/main/graphile-build/website/graphile-build/all-hooks.mdx","tags":[],"version":"5","lastUpdatedAt":1774370624000,"sidebarPosition":4,"frontMatter":{"layout":"page","path":"/graphile-build/all-hooks/","title":"All Hooks","sidebar_position":4},"sidebar":"tutorialSidebar","previous":{"title":"Hooks","permalink":"/graphile-build/5/hooks"},"next":{"title":"The Build Object","permalink":"/graphile-build/5/build-object"}}');var r=i(1085),l=i(1184),s=i(9445),a=i(7048);const o={layout:"page",path:"/graphile-build/all-hooks/",title:"All Hooks",sidebar_position:4},d=void 0,c={},p=[{value:"Registering a schema hook",id:"registering-a-schema-hook",level:2},{value:"Hook list",id:"hook-list",level:2},{value:"Specification",id:"specification",level:2},{value:"AllHooksNoopPlugin",id:"allhooksnoopplugin",level:2}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,l.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h2,{id:"registering-a-schema-hook",children:"Registering a schema hook"}),"\n",(0,r.jsxs)(n.p,{children:["Registering a hook is done via a graphile-config plugin via the\n",(0,r.jsx)(n.code,{children:"plugin.schema.hooks.*"})," object:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-ts",children:'import type {} from "graphile-build";\n\nexport const ExampleFieldsHookPlugin: GraphileConfig.Plugin = {\n  name: "ExampleFieldsHookPlugin",\n  schema: {\n    hooks: {\n      // Hooks go here, e.g.:\n      GraphQLObjectType_fields(fields, build, context) {\n        // ...\n        return fields;\n      },\n    },\n  },\n};\n'})}),"\n",(0,r.jsxs)(n.p,{children:["See ",(0,r.jsx)(n.a,{href:"#allhooksnoopplugin",children:"AllHooksNoopPlugin"})," for a more complete example."]}),"\n",(0,r.jsx)(n.h2,{id:"hook-list",children:"Hook list"}),"\n",(0,r.jsx)(n.p,{children:"The following hooks are currently supported:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"build"}),": Extend the ",(0,r.jsx)(n.code,{children:"build"})," object. Do not construct GraphQL types here."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"init"}),": Register types via ",(0,r.jsx)(n.code,{children:"build.registerType"}),"."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLSchema"}),": Configure the schema root types and options."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLSchema_types"}),": Add named types that are not otherwise referenced\n(typically interface implementations)."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType"}),": Extend object type configuration."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_interfaces"})," (deferred): Add interfaces to the object type."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_fields"})," (deferred): Add fields to the object type."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_fields_field"}),": Adjust a single field config."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_fields_field_args"}),": Add arguments to the field."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_fields_field_args_arg"}),": Adjust a single argument config."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInputObjectType"}),": Extend input object configuration."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInputObjectType_fields"})," (deferred): Add fields to the input object."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInputObjectType_fields_field"}),": Adjust a single input field config."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLEnumType"}),": Extend enum configuration."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLEnumType_values"}
1)," (deferred): Add or adjust enum values."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLEnumType_values_value"}),": Adjust a single enum value config."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLUnionType"}),": Extend union configuration."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLUnionType_types"})," (deferred): Add types to the union."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType"}),": Extend interface configuration."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_interfaces"})," (deferred): Add interfaces to the interface."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_fields"})," (deferred): Add fields to the interface."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_fields_field"}),": Adjust a single field config."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_fields_field_args"}),": Add arguments to the field."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_fields_field_args_arg"}),": Adjust a single argument config."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLScalarType"}),": Extend scalar configuration."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"finalize"}),": Perform assertions, or inspect/wrap/replace the built schema."]}),"\n"]}),"\n",(0,r.jsx)(n.p,{children:"Children of a hook run during the parent hook (unless deferred)."}),"\n",(0,r.jsxs)(n.p,{children:["The deferred hooks are called after the type instance is constructed (GraphQL\nuses a thunk callback), which allows for cyclic references or referencing the\ntype itself via ",(0,r.jsx)(n.code,{children:"context.Self"}),". GraphQL calls the thunk when the relevant\nproperty is needed, which can still be in the same tick."]}),"\n",(0,r.jsx)(n.h2,{id:"specification",children:"Specification"}),"\n",(0,r.jsx)(n.p,{children:'The first argument to each hook is the "specification" that is to be\nmanipulated. For most hooks this will be an object, but for some it will be an\narray. Here\'s the specification type for each hook:'}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"build"})," - ",(0,r.jsx)(n.code,{children:"Build"})," (the current build object)"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"init"})," - ",(0,r.jsx)(n.code,{children:"Record<string, never>"})," (an empty object)"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLSchema"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlschema",children:(0,r.jsx)(n.code,{children:"GraphQLSchemaConfig"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLSchema_types"})," - ",(0,r.jsx)(n.code,{children:"GraphQLNamedType[]"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType"})," - ",(0,r.jsx)(n.code,{children:"GraphileBuild.GrafastObjectTypeConfig"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_interfaces"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlinterfacetype",children:(0,r.jsx)(n.code,{children:"GraphQLInterfaceType[]"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_fields"})," - ",(0,r.jsx)(n.code,{children:"GraphileBuild.GrafastFieldConfigMap"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_fields_field"})," - ",(0,r.jsx)(n.code,{children:"GraphileBuild.GrafastFieldConfig"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_fields_field_args"})," -\n",(0,r.jsx)(n.code,{children:"GraphileBuild.GrafastFieldConfigArgumentMap"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLObjectType_fields_field_args_arg"})," -\n",(0,r.jsx)(n.code,{children:"GraphileBuild.GrafastArgumentConfig"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInputObjectType"})," - ",(0,r.jsx)(n.code,{children:"GraphileBuild.GrafastInputObjectTypeConfig"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInputObjectType_fields"})," -\n",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlinputobjecttype",children:(0,r.jsx)(n.code,{children:"GraphQLInputFieldConfigMap"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInputObjectType_fields_field"})," -\n",(0,r.jsx)(n.code,{children:"GraphileBuild.GrafastInputFieldConfig"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLEnumType"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlenumtype",children:(0,r.jsx)(n.code,{children:"GraphQLEnumTypeConfig"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLEnumType_values"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlenumtype",children:(0,r.jsx)(n.code,{children:"GraphQLEnumValueConfigMap"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLEnumType_values_value"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlenumtype",children:(0,r.jsx)(n.code,{children:"GraphQLEnumValueConfig"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLUnionType"})," - ",(0,r.jsx)(n.code,{children:"GraphileBuild.GrafastUnionTypeConfig"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLUnionType_types"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlobjecttype",children:(0,r.jsx)(n.code,{children:"GraphQLObjectType[]"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType"})," - ",(0,r.jsx)(n.code,{children:"GraphileBuild.GrafastInterfaceTypeConfig"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_interfaces"})," -\n",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlinterfacetype",children:(0,r.jsx)(n.code,{children:"GraphQLInterfaceType[]"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_fields"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlobjecttype",children:(0,r.jsx)(n.code,{children:"GraphQLFieldConfigMap"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_fields_field"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlobjecttype",children:(0,r.jsx)(n.code,{children:"GraphQLFieldConfig"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_fields_field_args"})," -\n",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlobjecttype",children:(0,r.jsx)(n.code,{children:"GraphQLFieldConfigArgumentMap"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLInterfaceType_fields_field_args_arg"})," -\n",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlobjecttype",children:(0,r.jsx)(n.code,{children:"GraphQLArgumentConfig"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"GraphQLScalarType"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlscalartype",children:(0,r.jsx)(n.code,{children:"GraphQLScalarTypeConfig"})})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"finalize"})," - ",(0,r.jsx)(n.a,{href:"https://graphql.org/graphql-js/type/#graphqlschema",children:(0,r.jsx)(n.code,{children:"GraphQLSchema"})})]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"allhooksnoopplugin",children:"AllHooksNoopPlugin"}),"\n",(0,r.jsx)(n.p,{children:"This plugin doesn't do anything, it's merely present to demonstrate the usage of\nthe various hooks."}),"\n","\n",(0,r.jsx)(a.A,{language:"ts",children:s.A.replace(/^[\s\S]*?\/\*{10,}\//,"").trim()})]})}function u(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},9445(e,n,i){i.d(n,{A:()=>t});const t='/* eslint-disable @typescript-eslint/no-unused-vars */\n/*\n * This file is purely for documentation, it doesn\'t _do_ anything and isn\'t\n * exported.\n */\n\n// Everything below this line will be output in the docs at\n// http://build.graphile.org/graphile-build/next/all-hooks\n/******************************************************************************/\nimport type {} from "graphile-build";\n\n// Declaration merging to expand hooked types\ndeclare global {\n  namespace GraphileBuild {\n    interface Build {\n      // Declare extra properties added via `plugin.schema.hooks.build` here\n    }\n  }\n}\n\nexport const AllHooksNoopPlugin: GraphileConfig.Plugin = {\n  name: "AllHooksNoopPlugin",\n  description:\n    "This plugin doesn\'t make any changes, just demonstrates all the schema hooks",\n  schema: {\n    hooks: {\n      build(mutableBuild, build, context) {\n        // This hook is for adding helpers to the `GraphileBuild.Build` object\n        // that will be accessible by all other hooks.\n\n        // NOTE: use declaration merging to add your new properties to the\n        // GraphileBuild.Build TypeScript type (see above)\n\n        // NOTE: `mutableBuild === build` at this point\
1n\n        return mutableBuild;\n      },\n      init(_, build, context) {\n        // Ensure no changes are actually made:\n        if (Math.random() < 2) return _;\n\n        // NOTE: `_` should not be modified or replaced; init phase is for\n        // registering types/etc\n\n        build.registerObjectType(\n          "MyObjectType",\n          {\n            // Add extra details to scope so later plugins can hook it here\n          },\n          () => {\n            return {\n              description: "...",\n              fields: {\n                // ...\n              },\n            };\n          },\n          "Reason we\'re defining this object type",\n        );\n\n        return _;\n      },\n\n      GraphQLSchema(schema, build, context) {\n        // Here\'s where you can add a query/mutation/subscription type to\n        // the schema, or add schema extensions.\n\n        if (Math.random() > 2) {\n          // To add extensions to the schema, mutate directly\n          schema.extensions = build.extend(\n            schema.extensions ?? {},\n            {\n              // Add extensions here:\n              myExtension: 27,\n            },\n            "Reason extensions are being added",\n          );\n        }\n\n        return build.extend(\n          schema,\n          {\n            // Add operation types here:\n            // query: build.getTypeByName("Query"),\n            // mutation: build.getTypeByName("Mutation"),\n            // subscription: build.getTypeByName("Subscription"),\n          },\n          "Reason we\'re adding an operation type",\n        );\n      },\n      GraphQLSchema_types(types, build, context) {\n        // NOTE: the schema config is at context.config (but don\'t mutate it)\n\n        return build.append(\n          types,\n          [\n            // Add types here that aren\'t discoverable by walking the root\n            // operation types - i.e. implementations of interfaces (`type Foo\n            // implements Iface {...}`) where that type may not ever otherwise\n            // be referenced.\n          ],\n          "name",\n          "Reason we\'re adding types to the schema",\n          "recoverable",\n        );\n      },\n\n      GraphQLObjectType(objectType, build, context) {\n        if (objectType.name !== "__MyObject__") return objectType;\n\n        objectType.description ??= "Some default description";\n        // Or mod extensions as in GraphQLSchema hook\n\n        return objectType;\n      },\n      GraphQLObjectType_interfaces(interfaces, build, context) {\n        if (context.Self.name !== "__MyObject__") return interfaces;\n\n        // This hook is to add additional interfaces to the given object type.\n\n        return build.append(\n          interfaces,\n          [\n            // Add interface types here:\n            // build.getTypeByName("InterfaceTypeName"),\n          ],\n          "name",\n          "Description of why we\'re adding interfaces",\n          "recoverable",\n        );\n      },\n      GraphQLObjectType_fields(fields, build, context) {\n        if (context.Self.name !== "__MyObject__") return fields;\n\n        const {\n          graphql: { isOutputType },\n          inflection,\n        } = build;\n\n        // This hook is meant for adding fields to object type context.Self\n\n        const fieldName = inflection.camelCase(\n          inflection.coerceToGraphQLName("..."),\n        );\n        const FieldType = build.getTypeByName("...");\n        if (!isOutputType(FieldType)) {\n          throw new Error("...");\n        }\n\n        // Adds the field to `fields`\n        return build.extend(\n          fields,\n          {\n            [fieldName]: context.fieldWithHooks(\n              // "scope" additions, available in context.scope in hooks below\n              {\n                fieldName, // Required\n                // Add extra scope info here\n              },\n\n              // The field spec itself:\n              {\n                type: FieldType,\n                description: "...",\n                args: {\n                  /* ... */\n                },\n                // ...\n              },\n            ),\n          },\n          "Description of why we\'re adding fields",\n        );\n      },\n      // For the following GraphQLObjectType_fields_field* hooks, the field name\n      // is available at `context.scope.fieldName`\n      GraphQLObjectType_fields_field(field, build, context) {\n        if (\n          context.Self.name !== "__MyObject__" ||\n          context.scope.fieldName !== "__myField__"\n        ) {\n          return field;\n        }\n\n        // Your chance to mutate the field spec, e.g.:\n        field.deprecationReason ??= "I just don\'t like it";\n\n        return field;\n      },\n      GraphQLObjectType_fields_field_args(args, build, context) {\n        if (\n          context.Self.name !== "__MyObject__" ||\n          context.scope.fieldName !== "__myField__"\n        ) {\n          return args;\n        }\n\n        const {\n          inflection,\n          graphql: { isInputType },\n        } = build;\n        const argName = inflection.camelCase(\n          inflection.coerceToGraphQLName("..."),\n        );\n        const ArgType = build.getTypeByName("...");\n        if (!isInputType(ArgType)) {\n          throw new Error("...");\n        }\n\n        return build.extend(\n          args,\n          {\n            // Add more arguments here\n            [argName]: {\n              type: ArgType,\n              description: "...",\n            },\n          },\n          "Reason we\'re adding args",\n          "throw",\n        );\n      },\n      GraphQLObjectType_fields_field_args_arg(arg, build, context) {\n        if (\n          context.Self.name !== "__MyObject__" ||\n          context.scope.fieldName !== "__myField__" ||\n          context.scope.argName !== "__myArg__"\n        ) {\n          return arg;\n        }\n\n        // Your chance to mutate the arg spec, e.g.:\n        arg.deprecationReason ??= "I just don\'t like it";\n\n        return arg;\n      },\n\n      GraphQLInterfaceType(interfaceType, build, context) {\n        // Essentially identical to GraphQLObjectType but for interfaces\n        return interfaceType;\n      },\n      GraphQLInterfaceType_interfaces(interfaces, build, context) {\n        // Essentially identical to GraphQLObjectType_interfaces but for interfaces\n        return interfaces;\n      },\n      GraphQLInterfaceType_fields(fields, build, context) {\n        // Essentially identical to GraphQLObjectType_fields but for interfaces\n        return fields;\n      },\n      GraphQLInterfaceType_fields_field(field, build, context) {\n        // Essentially identical to GraphQLObjectType_fields_field but for interfaces\n        return field;\n      },\n      GraphQLInterfaceType_fields_field_args(args, build, context) {\n        // Essentially identical to GraphQLObjectType_fields_field_args but for interfaces\n        return args;\n      },\n      GraphQLInterfaceType_fields_field_args_arg(arg, build, context) {\n        // Essentially identical to GraphQLObjectType_fields_field_args_arg but for interfaces\n        return arg;\n      },\n\n      GraphQLInputObjectType(inputObjectType, build, context) {\n        if (inputObjectType.name !== "__MyInputObject__") {\n          return inputObjectType;\n        }
1\n\n        inputObjectType.description ??= "Some default description";\n        // Or mod extensions as in GraphQLSchema hook\n\n        return inputObjectType;\n      },\n      GraphQLInputObjectType_fields(fields, build, context) {\n        if (context.Self.name !== "__MyInputObject__") {\n          return fields;\n        }\n\n        const {\n          graphql: { isInputType },\n          inflection,\n        } = build;\n\n        // This hook is meant for adding fields to input object type context.Self\n\n        const myName = "...";\n        const fieldName = inflection.camelCase(\n          inflection.coerceToGraphQLName(myName),\n        );\n        const FieldType = build.getTypeByName("...");\n        if (!isInputType(FieldType)) {\n          throw new Error("...");\n        }\n\n        // Adds the field to `fields`\n        return build.extend(\n          fields,\n          {\n            [fieldName]: context.fieldWithHooks(\n              // "scope" additions, available in context.scope in hooks below\n              {\n                fieldName, // Required\n                // Add extra scope info here\n              },\n\n              // The field spec itself:\n              {\n                type: FieldType,\n                description: "...",\n                // ...\n              },\n            ),\n          },\n          "Description of why we\'re adding fields",\n        );\n      },\n      GraphQLInputObjectType_fields_field(field, build, context) {\n        if (\n          context.Self.name !== "__MyInputObject__" ||\n          context.scope.fieldName !== "__myField__"\n        ) {\n          return field;\n        }\n\n        field.description ??= "Some default description";\n\n        return field;\n      },\n\n      GraphQLEnumType(enumType, build, context) {\n        if (enumType.name !== "__MyEnum__") return enumType;\n\n        enumType.description ??= "Some default description";\n        // Or mod extensions as in GraphQLSchema hook\n\n        return enumType;\n      },\n      GraphQLEnumType_values(values, build, context) {\n        if (context.Self.name !== "__MyEnum__") return values;\n\n        const { inflection } = build;\n\n        const valueName = inflection.constantCase(\n          inflection.coerceToGraphQLName("Twenty seven"),\n        );\n\n        return build.extend(\n          values,\n          {\n            [valueName]: {\n              value: 27,\n              description: "Represents 27 of something",\n              // ...\n            },\n          },\n          "Reason we\'re adding values",\n        );\n      },\n      GraphQLEnumType_values_value(value, build, context) {\n        if (\n          context.Self.name !== "__MyEnum__" ||\n          context.scope.valueName !== "TWENTY_SEVEN"\n        ) {\n          return value;\n        }\n\n        value.deprecationReason = "I just don\'t like it";\n\n        return value;\n      },\n\n      GraphQLUnionType(unionType, build, context) {\n        if (unionType.name !== "__MyUnion__") return unionType;\n\n        unionType.description ??= "Some default description";\n        // Or mod extensions as in GraphQLSchema hook\n\n        return unionType;\n      },\n      // For the following GraphQLUnionType_* hooks, the union type instance\n      // is available at `context.Self`\n      GraphQLUnionType_types(types, build, context) {\n        if (context.Self.name !== "__MyUnion__") return types;\n\n        return build.append(\n          types,\n          [\n            // Add object types here:\n            // build.getTypeByName("ObjectTypeName"),\n          ],\n          "name",\n          "Description of why we\'re adding types",\n          "recoverable",\n        );\n      },\n\n      // NOTE: you cannot hook the builtin scalars `Boolean`, `Int`, `Float`,\n      // `ID`, `String`\n      GraphQLScalarType(scalarType, build, context) {\n        if (scalarType.name !== "__MyScalar__") {\n          return scalarType;\n        }\n\n        scalarType.description ??= "Some default description";\n        // Or mod extensions as in GraphQLSchema hook\n\n        return scalarType;\n      },\n\n      finalize(constructedSchema, build, context) {\n        // NOTE: never perform mutations in this hook, the schema has already\n        // been built! It\'s primarily useful for performing assertions to catch\n        // development errors.\n\n        return constructedSchema;\n      },\n    },\n  },\n};\n'}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.