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

Make graphql-anywhere filter function generic #3929

Merged

Conversation

minznerjosh
Copy link
Contributor

A common part of many GraphQL/TypeScript setups is automatically generating TypeScript typings for any queries/mutations/fragments in the source code. For example, at Trialspark, we're using graphql-code-generator.

It would be great to more easily leverage the interfaces that tool is generating for our GraphQL fragments when using the filter() function from graphql-anywhere.

This PR makes filter() generic on two, optional type arguments. The first represents the filtered data that is returned; the second represents the larger superset of data that is passed. This way, we can pass the autogenerated typings for our fragments to the filter()s that use those fragments:

import { MyFragment, MyBigQuery } from './generated-types';

const FRAGMENT = gql`
  fragment MyFragment on Thing {
    id
    foo
  }
`
const lotsOfData = { /* pretend there's a lot here */};
const data = filter<MyFragment, MyBigQuery>(FRAGMENT, lotsOfData);

data.foo // fine
data.bar // not fine

@apollo-cla
Copy link

@minznerjosh: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea @minznerjosh - thanks!

@hwillson hwillson merged commit 8606e5b into apollographql:master Sep 19, 2018
@minznerjosh minznerjosh deleted the josh__make-filter-function-generic branch September 19, 2018 16:05
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants