You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue is apollo codegen throw UnkonwFragment error if fragment is imported from other package.
Intended outcome:
One of my monorepo packages exports fragment field on exported react component like here:
// monorepo/packages/Email/src/index.tsximportgqlfrom'graphql-tag';interfaceProps{data: Data// generated as expected by codegen}constEmail=({data}: Props)=><span>email is {data.email}</span>Email.fragment=gql` fragment Email on Query { __typename email }`exportdefaultEmail
so after building (just ts compiler) I want to use this package:
// monorepo/demo/src/index.tsximportgqlfrom'graphql-tag';importEmailfrom'email'constApp=({data})=><Emaildata={data}/>App.fragment=gql` fragment App on Query { ...Email }${Email.fragment}`
I expected that runing apollo codegen in application will generate proper type for data prop in App. Regardless this code works fine and data is fetched exactly as expected.
Actual outcome:
Instead of proper code generation i got `unkown fragment error:
.../monorepo/demo/src/index.tsx: Unknown fragment "EmailPreview_data".
{ ToolError: Validation of GraphQL query document failed
I found two options to get this working.
Apollo codegen can't find the fragments schema because it's not in the search path.
Option: You move codegen to the root of your project and let it generate the type definitions for all packages.
Option: You add the fragments to your includes.
I went with the second option because I still want the global types separated for each package.
This is my apollo config for the app that wants to import the fragments:
The only caveat is now that it generates the types for my includes package schemas too every time I run codegen on the app. Nice would be an option like external schemas where it's posible to import external schema defenitions.
The issue is apollo codegen throw
UnkonwFragment
error if fragment is imported from other package.Intended outcome:
One of my monorepo packages exports fragment field on exported react component like here:
so after building (just ts compiler) I want to use this package:
I expected that runing apollo codegen in application will generate proper type for
data
prop inApp
. Regardless this code works fine and data is fetched exactly as expected.Actual outcome:
Instead of proper code generation i got `unkown fragment error:
Versions
The text was updated successfully, but these errors were encountered: