Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entities that reference each other. #8

Open
Davenporten opened this issue Dec 10, 2020 · 0 comments
Open

Entities that reference each other. #8

Davenporten opened this issue Dec 10, 2020 · 0 comments

Comments

@Davenporten
Copy link

This question might be really dumb, I'm just trying to wrap my head around how federation works (I'm also relatively new to GraphQL, but have a little experience).

So in the video where you used this repo astronauts.js never references Mission as an external entity, rather, to be able to get missions from an Astronaut you have

  Astronaut: {
    async missions(astronaut) {
      const res = await fetch(`${apiUrl}/missions`);
      const missions = await res.json();

      return missions.filter(({ crew }) =>
        crew.includes(parseInt(astronaut.id))
      );
    }
  },

a direct call to the missions server and filtering through the result. My question is, why couldn't you do something like this in astronaut.js

    extend type Mission @key(fields: "id") {
        id: ID! @external
        crew: [Astronaut]
    }

along with all the appropriate resolver and changes in missions.js to make make it so the direct query and filtering aren't necessary. I tried this and was just getting back entities like { __typename: 'Mission', id: 2} so I know it doesn't work, but I don't understand why it doesn't work.

I hope these questions make sense. Thanks so much for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant