External fragments are not pulled into the query document using the loader.
See original GitHub issueThe fragments are not pulled into the query document using the loader.
Example:
# ContactFragment.gql
fragment Contact on ContactType {
phone
email
}
# UserInfo.gql
fragment UserInfo on UserInfoType {
id
name
contact {
address
...Contact
}
}
# User.gql
query User($email: String) {
user(email: $email) {
...UserInfo
}
}
# Users.gql
query Users($emails: [String]) {
users(emails: $emails) {
...UserInfo
}
}
// Both of the following Nodes fail when used with apollo client.
The error is: `Unknown fragment \"UserInfo\".`
const UserQueryNode: DocumentNode = require('graphql-tag/loader!../../graphql/User.gql');
const UsersQueryNode: DocumentNode = require('graphql-tag/loader!../../graphql/Users.gql');
The apollo-codegen
handles the above scenario well when generating the schema.ts file.
However, graphql-tag/loader
is unable to insert the fragments in this example.
One thing to notice is that graphql-tag/loader
works well when the fragments are also located in the same file as the query that is referencing them.
The fragments should be pulled in via the loader, however, that is not the case as per this issue.
So, we need the fragments to be in separate files and apollo-codegen
handles them properly when compiling the schema.ts. We just have to ensure that the loader
in this module is also properly including them in each query.
===== Version: “graphql-tag”: “^1.2.4”, node: 6.9.5 os: darwin x64
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top GitHub Comments
You can use the new import syntax, as in:
Does that help?
Same issue here. I was able to add the
graphql-tag/loader
to Angular CLI’s webpack build without ejecting using ngx-build-plus.webpack.partial.js
: