question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

External fragments are not pulled into the query document using the loader.

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
czertcommented, Feb 23, 2017

You can use the new import syntax, as in:

#import "./UserInfo.gql"
query Users($emails: [String]) {
...

Does that help?

2reactions
ravishivtcommented, Feb 8, 2019

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:

module.exports = {
  module: {
    rules: [
      {
        test: /\.(graphql|gql)$/,
        exclude: /node_modules/,
        loader: 'graphql-tag/loader',
      },
    ],
  },
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using fragments - Apollo GraphQL Docs
The most straightforward use of fragments is to reuse parts of queries (or mutations or subscriptions) in various parts of your application.
Read more >
Advanced Topics on Caching – Angular
Since these queries are cached by both the initial query and their parameters, a problem arises when later retrieving or updating paginated ...
Read more >
Migrating from v3.x to v4.x - GraphQL .NET
Once the asynchronous field resolver or data loader returns its final result, the context will be cleared and may be re-used.
Read more >
Redux Essentials, Part 8: RTK Query Advanced Patterns
How to use tags with IDs to manage cache invalidation and refetching; How to work with the RTK Query cache outside of React ......
Read more >
SQL Developer Concepts and Usage - Oracle Help Center
If you do not use the drop-down arrow to specify the database connection to use, ... Close Other Documents: Closes all open windows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found