Sorry if this is a bit involved, but I'm really trying to close the last mile on being able to use Apollo Client for local as well as server state, with automatic Typescript everywhere. To wit, I have a query like this:
query NavigationBarQuery($userId: Int, $portfolioCompanyId: Int!) {
user(id: $userId) {
id
firstName
lastName
company {
... on CompanyInterface {
companyType
}
}
}
}
That is being imported by my NavigationBar component like so:
import { NavigationBarQuery, NavigationBarQueryVariables } from '../../../graphql/generated/NavigationBarQuery';
import NAVIGATION_BAR_QUERY from '../../../graphql/NavigationBarQuery.graphql';
const NavigationBar = (vars: NavigationBarQueryVariables) => (
<Query query={NAVIGATION_BAR_QUERY} variables={vars}>
{({ loading, error, data, client }: QueryResult<INavigationBarClientQuery>) => {
// etc.
Generation is performed with a local schema file (dumped from Graphene) like so:
apollo client:codegen --localSchemaFile ./build/schema.json --includes './src/graphql/**' --target typescript
This works great, I get TypeScript types and everything.
However, I'd like to include some local state, with a query like this:
query NavigationBarQuery($userId: Int, $portfolioCompanyId: Int!) {
user(id: $userId) {
id
firstName
lastName
company {
... on CompanyInterface {
companyType
}
}
}
showNavbarUserInfo @client
}
This query works just fine if I bypass TypeScript, but when I attempt to generate Typescript definitions for it, the generation script emits this error:
.../client/src/graphql/NavigationBarQuery.graphql: Cannot query field "showNavbarUserInfo" on type "Query".
{ ToolError: Validation of GraphQL query document failed
at Object.validateQueryDocument (/Users/gavin/.config/yarn/global/node_modules/apollo-language-server/lib/errors/validation.js:32:19)
at Object.generate [as default] (/Users/gavin/.config/yarn/global/node_modules/apollo/lib/generate.js:19:18)
at write (/Users/gavin/.config/yarn/global/node_modules/apollo/lib/commands/client/codegen.js:64:54)
at Task.task (/Users/gavin/.config/yarn/global/node_modules/apollo/lib/commands/client/codegen.js:83:46) name: 'ToolError' }
What, if anything, is the workaround for this? As per usual, looking for examples.