Named Operations Object
Generates an object containing a list of all your GraphQL operations and fragments. This is useful if you are using Apollo-Client and wish to have type validation when you are using `refetchQueries`.
- Version
- 4.0.1
- Weekly downloads
- 204k
- License
- MIT
- Updated
- Apr 19, 2026
Installation
npm i -D @graphql-codegen/named-operations-object
yarn add -D @graphql-codegen/named-operations-object
pnpm add -D @graphql-codegen/named-operations-object
bun add -D @graphql-codegen/named-operations-object
Config API Reference
identifierName
type: string
Allow you to customize the name of the exported identifier Default value: “namedOperations”
useConsts
type: boolean
Will generate a const string instead of regular string. Default value: “false”
throwOnDuplicate
type: boolean
Throws an error if a duplicate operation name is found. Default value: “false”
This plugin generates an object containing a list of all your GraphQL operations and fragments. This
is useful if you are using Apollo-Client and wish to have type validation when you are using
refetchQueries.
All operations and fragments are being exported by their name (so unnamed operations are being ignored), in the following structure:
How to use?
Include the plugin within your output (into an existing .js/.ts file, or a new file), for
example:
Refetch queries without input parameters
From this point, you should be able to import namedOperations from that file, and use the names
within your code. For example, with Apollo Client and a refetch query that has no input parameters,
you can simply add the named operation to the refetchQueries array:
Refetch queries with input parameters
For refetch queries that contain input parameters, instead of adding a named operation to the
refetchQueries array, you need to add an Apollo
QueryOptions object. The query
value inside the QueryOptions object does not take one of the entries in the namedOperations
list. Instead, the query value takes a TypedDocument constant which corresponds to your query
and should be generated by default.
A refetchQueries array that contains multiple queries, some of which contain input parameters,
might look something like this: