After migrating my project's codebase from using the direct Headless Wordpress GraphQL endpoint to OneGraph for Google+Facebook Business support, I encountered an error related to apollo referencing the output codegen. Here is the specific error message:
graphQLErrors: [
{
message: 'Variable "$idTypeFoot" got invalid value 2; Expected type MenuNodeIdTypeEnum.',
path: [Array],
extensions: [Object]
},
{
message: 'Variable "$idTypeFoot" got invalid value 2; Expected type MenuNodeIdTypeEnum.',
path: [Array],
extensions: [Object]
}
],
The generated/graphql.tsx file contains the output codegen definition as follows:
export enum WordpressMenuNodeIdTypeEnum {
/** Identify a menu node by the Database ID. */
DATABASE_ID = 0,
/** Identify a menu node by the (hashed) Global ID. */
ID = 1,
/** Identify a menu node by it's name */
NAME = 2
}
Prior to the migration to OneGraph, the enum was defined like this:
/** The Type of Identifier used to fetch a single node. Default is "ID". To be used along with the "id" field. */
export enum MenuNodeIdTypeEnum {
/** Identify a menu node by the Database ID. */
DatabaseId = 'DATABASE_ID',
/** Identify a menu node by the (hashed) Global ID. */
Id = 'ID',
/** Identify a menu node by its name */
Name = 'NAME'
}
The dynamic-nav-fields.graphql
partial used in the parent query:
fragment DynamicNavFragment on WordpressMenuItem {
id
label
path
parentId
}
The parent query in dynamic-nav.graphql
:
# import DynamicNavFragment from './Partials/dynamic-nav-fields.graphql'
query DynamicNav(
$idHead: ID!
$idTypeHead: WordpressMenuNodeIdTypeEnum!
$idFoot: ID!
$idTypeFoot: WordpressMenuNodeIdTypeEnum!
) {
Header: wordpress {
menu(id: $idHead, idType: $idTypeHead) {
menuItems(where: { parentId: 0 }) {
edges {
node {
...DynamicNavFragment
childItems {
edges {
node {
...DynamicNavFragment
childItems {
edges {
node {
...DynamicNavFragment
}
}
}
}
}
}
}
}
}
}
}
Footer: wordpress {
menu(id: $idFoot, idType: idTypeFoot) {
menuItems(where: { parentId: 0 }) {
edges {
node {
...DynamicNavFragment
childItems {
edges {
node {
...DynamicNavFragment
}
}
}
}
}
}
}
}
}
The configuration in codegen.yml file is set up like this:
overwrite: true
schema:
${WORDPRESS_API_URL_YML}:
headers:
Authorization: Bearer ${WORDPRESS_AUTH_REFRESH_TOKEN_YML}
documents: 'graphql/**/*.graphql'
generates:
graphql/generated/graphql.tsx:
plugins:
- typescript:
constEnums: false
enumsAsTypes: false
numericEnums: true
futureProofEnums: false
enumsAsConst: false
onlyOperationTypes: false
maybeValue: T | null | undefined
noExport: false
enumPrefix: true
fieldWrapperValue: T
wrapFieldDefinitions: true
skipTypename: false
nonOptionalTypename: false
useTypeImports: false
avoidOptionals: true
declarationKind:
input: interface
type: interface
- typescript-operations:
declarationKind:
input: interface
type: interface
avoidOptionals: true
exportFragmentSpreadSubTypes: true
- typescript-react-apollo:
addDocBlocks: true
reactApolloVersion: 3
documentMode: documentNodeImportFragments
config:
maybeValue: T | null | undefined
declarationKind:
input: interface
type: interface
documentNodeImportFragments: true
reactApolloVersion: 3
withHooks: true
withHOC: false
avoidOptionals: true
withComponent: false
exportFragmentSpreadSubTypes: true
addDocBlocks: true
graphql/graphql.schema.graphql:
plugins:
- schema-ast
config:
commentDescriptions: true
graphql/graphql.schema.json:
plugins:
- introspection
config:
commentDescriptions: true
hooks:
afterAllFileWrite:
- prettier --write
I am seeking assistance in resolving why OneGraph replaces the generated Enum values with numbers that Apollo client cannot read. Any insights on how to address this issue would be greatly appreciated.