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

FilterToSchema doesn't remove empty selection sets #826

Closed
adamkl opened this issue Jun 1, 2018 · 1 comment
Closed

FilterToSchema doesn't remove empty selection sets #826

adamkl opened this issue Jun 1, 2018 · 1 comment

Comments

@adamkl
Copy link
Contributor

adamkl commented Jun 1, 2018

Intended outcome:
Given target schema:

type Query {
  customer: Customer
}

type Customer {
  name: String
  address: Address
}

type Address {
  street: String
  city: String
  country: String
}

And query:

query CustomerQuery {
  customer {
    name
    address {
      planet
    }
  }
}

FilterToSchema leaves behind an empty selection set which fails validation on a remote graphql server:

query CustomerQuery {
  customer {
    name
    address
  }
}

Actual outcome:
FilterToSchema should remove fields with empty selection sets:

query CustomerQuery {
  customer {
    name
  }
}

How to reproduce the issue:
I'm preparing a PR based on this branch which includes unit tests that reproduce the error and some code changes to resolve it.

@adamkl
Copy link
Contributor Author

adamkl commented Jun 1, 2018

As an addendum to this, I'm sure there are other scenarios that I haven't accounted for (empty selection sets on inline fragments?), and I can see the code for this getting more complex over time. A friend of mine (@brysgo) tackled this problem by leveraging GraphQL's built in validation. It might be prudent to take a look at his approach (graphql-mask)

adamkl added a commit to adamkl/graphql-tools that referenced this issue Jun 1, 2018
stubailo pushed a commit that referenced this issue Jul 31, 2018
* filter empty selections sets in FilterToSchema (#826)

* update changelog.md
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