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.

Additional fields on Relay connection plugin global config

See original GitHub issue

Hi all,

There is a potential bug for additional extended fields (e.g.: totalCount) added globally on the on the Relay connection plugin when there’s a nested connection of the same type as the parent. I’ve created a small repo that reproduces the behavior: https://github.com/oliveiraethales/nexus-nested-totalcount-bug

It seems that configuring the totalCount in a one-off/per-field instead of in the global configuration of the plugin works properly; and the resulting schema is also different when doing so.

Any thoughts?

Thank you!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bentron2000commented, Nov 6, 2021

FWIW I got bitten with these changes moving from 1.0.0 to 1.1.0 with our extended connections with a totalCount field.

Documentation is not altogether clear and release notes don’t appear to clearly indicate this as a possibly breaking change between versions.

Documentation at Extending Connection / Edge types shows only the nodes version for a globally configured extension.

A use case where the connection is extended globally but provided by the resolve approach is not shown.

ie. it would require something like:

{
      ...
      resolve: ( root, args, ctx ) => {
        ...
        return { ...connectionFromArray( itemList, args ), totalCount: itemList.length}
      }
}
0reactions
tgriessercommented, Jul 27, 2021

@edufelipe - just looked at the code, currently, if you use the resolve syntax then you need to specify the totalCount on the object returned:

resolve: (root, args, ctx, info) => {
  return {
    ...connectionFromArray(
      [
        { id: "1", name: "John" },
        { id: "2", name: "Amy" },
      ],
      args
    ),
    totalCount: 2,
  };
}

If you use the nodes return, then the totalCount fn gets called:

totalCount: (root, args, ctx, info) => {
  // This code is always executed, replacing the would-be correct root 'people' connection totalCount value (which would be 2)
  console.log("totalCount friends", root);
  return 3;
},
nodes: (root, args, ctx, info) => {
  // This code also gets executed properly
  // console.log("resolve friends");
  return [
    { id: 3, name: "Jack" },
    { id: 4, name: "Jane" },
    { id: 5, name: "Ana" },
  ];
},

At some point I’ll look into whether it makes sense to change this behavior, but just wanted to give you an idea of how it works for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relay Connection - Plugins - GraphQL Nexus
The connection plugin provides a new method on the object definition builder, enabling paginated associations between types, following the Relay Connection ...
Read more >
Relay plugin for Pothos GraphQL
The relay plugin adds to new query fields node and nodes which can be used to directly fetch nodes using global IDs by...
Read more >
Relay Compiler - Relay Docs
Relay Modern uses the Relay Compiler to convert graphql literals into generated files that live alongside your source files. While you type queries...
Read more >
Building a Relay-Compliant Schema With Node/Express
Maybe you found dated examples of the proper compliant setup. Maybe you keep finding articles on the frontend side of Relay when you're ......
Read more >
Using with Relay — absinthe v1.7.0 - HexDocs
Relay expects you to provide a query field called node that accepts a global ID (as arg :id ) and returns the corresponding...
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