entria / ReactNavigationRelayModern

React Navigation integration with Relay
173 stars 23 forks source link

use @arguments and @argumentsDefinitions #16

Closed sibelius closed 5 years ago

ssomnoremac commented 6 years ago

Is there a breaking change on Relay 1.4 around this? I can't get an nearly identical UserList.js to work. I get this as the error. It's not all too clear

{"name":"RelayNetwork","type":"mustfix","framesToPop":2,"source":{"operation":{"fragment":{"argumentDefinitions":
[{"kind":"LocalArgument","name":"count","type":"Int!","defaultValue":null}],"kind":"Fragment","metadata":null,"name":"ShiftListQuery","selections":
[{"kind":"FragmentSpread","name":"ShiftList_query","args":null}],"type":"RootQueryType"},"id":null,"kind":"Batch","metadata":{},"name":"ShiftListQuery","query":{"argumentDefinitions":
[{"kind":"LocalArgument","name":"count","type":"Int!","defaultValue":null}],"kind":"Root","name":"ShiftListQuery","operation":"query","selections":[{"kind":"LinkedField","alias":null,"args": ...
sibelius commented 6 years ago

try to check this post https://medium.com/@sibelius/relay-modern-argumentdefinitions-d53769dbb95d

and this one https://medium.com/@andreicalazans/relay-is-just-getting-better-54112ffc1a9e

ssomnoremac commented 6 years ago

thanks, I actually realized that Relay expects or accounts for "data" as the root field of the fetch query response. I was doing response.json().data. I'll try to get a PR for this issue soon.

ssomnoremac commented 6 years ago

@sibelius , using @argumentDeinfitions in my app now and introduced a new arg

@argumentDefinitions(
  count: { type: "Int" },
  cursor: { type: "String" },
  employerId: { type: "ID!" }) {...

Relay compiler won't compile unless I pass a default even though I'm clearly passing the id here:

export default createQueryRenderer(
  EmployerOpeningListPaginationContainer,
  EmployerOpeningList, 
  {
    variables: {cursor: null, count: 10, employerId: 1 },
    query
  }
);

ERROR: RelayCompilerScope: No value found for required argument$employerId: ID!. any ideas?

sibelius commented 6 years ago

you need to use @arguments as well

@argumentDefinition will create local variables

employerId in your queryRenderer is a global one

...EmployerOpeningList_query @arguments(employerId: $employerId)

ssomnoremac commented 6 years ago

ok, nevermind, got it working with adding the arg to the outside query. Yup, you just said it. I still don't understand the global / local thing. Need to stare at this one file... for even longer :0 🍻

sibelius commented 5 years ago

we can improve this later on