1

When using REST data, our interfaces in Typescript React would appear like the following:

interface User {
  id: number;
  name: string;
  credentials: UserCredentials
}

interface UserCredentials {
  id: number;
  value: string;
}

However when we obtain the graphQL data from Relay, it appears as so:

query UserQuery {
    users {
      edges {
        node {
          id
          name
          credentials {
            edges {
              node {
                id
                value
                }
              }
            }
          }
        }
      }
    }
  }

I'd prefer to work with objects using the interfaces we have created, not those supplied by Relay's types. Other than creating a new User object after query retrieval, is there a better way to reconcile the differences between what Relay gives us and what we are working with? Or is everyone mapping over "edges" to render their data?

arano879n
  • 55
  • 3
  • check out this might help https://stackoverflow.com/questions/42622912/in-graphql-whats-the-meaning-of-edges-and-node – Dhavalkumar Prajapati Sep 28 '21 at 03:00
  • Does this answer your question? [What is the reason for having edges and nodes in a connection in your graphql schema?](https://stackoverflow.com/questions/42938472/what-is-the-reason-for-having-edges-and-nodes-in-a-connection-in-your-graphql-sc) – Dhavalkumar Prajapati Sep 28 '21 at 03:02
  • 1
    Thank you for your help. I feel I understand the utility of edges. My question is more focused on the typescript definitions and how this factors into manipulation of the data. Are people typically working directly with the typescript definitions generated automatically by Relay? – arano879n Sep 28 '21 at 03:13

0 Answers0