Skip to content

Provide utility to validate that an response match a given query #563

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

Open
ecstasy2 opened this issue Nov 10, 2016 · 2 comments
Open

Provide utility to validate that an response match a given query #563

ecstasy2 opened this issue Nov 10, 2016 · 2 comments

Comments

@ecstasy2
Copy link

When writing unit tests one need to mock any response that would otherwise come from the graphql server. Given that setting up the wrong expectation for the mocked payload can lead to writing tests against the wrong schema. A utility function that can be used to validate that a given object match a given query would be really useful to have.

Example payload used as a mock response:

{
  user: {
    id: 'some-id',
    name: 'Smith'
  }
}

The corresponding query is:

gql `query {
  user(id: $userId) {
    id
  }
}`

As you can see the mock response does not match the query and it would be nice to be able to assert on that.

I would be happy to submit a PR with this, but would like to know if there is a place I start looking and where is the right interface we might want to have for it.

@stubailo
Copy link

I have a few suggestions:

  1. You can use something like graphql-tools to use GraphQL for the mocking, that way your mock data will always match the schema.
  2. You can use graphql-anywhere to validate against the shape of the query, there's an open PR to add that to the library: https://github.com/apollostack/graphql-anywhere/pull/14/files#diff-80a85651dc5631fbc09228fdee410242R25

We do (1), and get our mock data from the queries directly so they are guaranteed to be consistent.

@leebyron
Copy link
Contributor

I like this idea, @ecstasy2. Right now there isn't something like this as we take it for granted (ie. there test cases covering) that the response of executing a query matches the query.

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

No branches or pull requests

3 participants