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

Error Cannot query field "node" on type "Query". after setVariables #1195

Closed
markogresak opened this issue Jun 1, 2016 · 2 comments
Closed

Comments

@markogresak
Copy link

markogresak commented Jun 1, 2016

Hi!

I'm using this query

fragments: {
  options: () => Relay.QL`
    fragment on diseaseMedicine @relay(plural: true) {
      value: id,
      label: disease
    }
  `
}

included as:

initialVariables: {
  disease: ''
},
fragments: {
  store: () => Relay.QL `
    fragment on Store {
      DiseaseOptions: diseaseMedicine {
        ${DiseaseSelect.getFragment('options')}
      },
      AllergyOptions: diet {
        ${AllergySelect.getFragment('options')}
      },
      MedicationOptions: diseaseMedicine {
        ${MedicationSelect.getFragment('options')}
      },
      DietOptions: diet {
        ${DietSelect.getFragment('options')}
      }
    }
  `
}

Which, after using .setVariables({disease: ...}), attempts to send this query:

query Index_StoreRelayQL($id_0: ID!) {
  node(id: $id_0) {
    ...F1
  }
}

fragment F0 on diseaseMedicine {
  id
  medicine
}

fragment F1 on Store {
  _diseaseMedicine14kzg6: diseaseMedicine {
    id
    ...F0
  }
  id
}

And it fails with error message Cannot query field "node" on type "Query".

However, if I were to change the above query (playing in graph_i_QL) to:

query Index_StoreRelayQL {
  store {
    ...F1
  }
}

fragment F0 on diseaseMedicine {
  id
  medicine
}

fragment F1 on Store {
  _diseaseMedicine14kzg6: diseaseMedicine {
    id
    ...F0
  }
  id
}

It executes correctly, except that it's not using the variable.

I am using react-relay v0.7.3. Also, I'm using react-router-relay v0.10.1 for routing and setting queries to:

{
  queries: {
    store: (component) => Relay.QL`
      query MainQuery {
        store { ${component.getFragment('store')} }
      }
    `
  }
}

Any ideas how to fix this?

@markogresak
Copy link
Author

Apparently moving the ${MedicationSelect.getFragment('options')} together with ${DiseaseSelect.getFragment('options')} into same field, as in:

options: diseaseMedicine {
  ${DiseaseSelect.getFragment('options')}
  ${MedicationSelect.getFragment('options')}
},

solves the problem I was having.
Can someone explain why this was happening?

@markogresak
Copy link
Author

The last comment didn't solve the problem fully, it was still missing using the variable as argument.

I have noticed that the graphQL schema was missing nodeDefinitions, as in there was no node: nodeField and no interfaces: [nodeInterface]. I should've looked through the tutorial more thoroughly.

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