0

I am trying to write a simple query with optional filter params

For example

const query = gql`query FilteredPeople($email: String) {
  people(email: $email) {
    fullName
    email
  }
}`;

I keep getting

"Network error: The inline argument "email" is expected as a variable but was not provided."

It makes me think it’s on the server side, but my schema is pretty straightforward

const RootQuery = `
    type RootQuery {
      people(email: String): [Person]
    }
`;

Looking at the graphql spec to specify if something is optional or not you use a !. As you can see email is not required.

Note I am using apollo client/server and react-apollo. Versions on my

server
    "graphql": "^0.7.2",
    "graphql-server-express": "^0.4.3",

client
    "apollo-client": "0.5.0",
    "graphql-tag": "0.1.15",
    "react-apollo": "0.5.16",

Am I missing something? I thought I fixed it, but it stopped working so I guess not.

Ryan-Neal Mes
  • 6,003
  • 7
  • 52
  • 77

2 Answers2

1

Although it looks like the String is nullable, it actually is if you decide not to pass anything in at all like so:

const query = gql`query {
  people {
    fullName
    email
  }
}`;

However if you do use pass in a parameter like you did in your question, then you must define that variable.

Hope that helps!

vince
  • 1,904
  • 1
  • 12
  • 17
0

After further investigation it seems like this is expected behaviour.

http://facebook.github.io/graphql/#sec-All-Variables-Used

Operation variables must be used when defining an operation.

Ryan-Neal Mes
  • 6,003
  • 7
  • 52
  • 77