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

babel plugin - support introspection fields #280

Conversation

josephsavona
Copy link
Contributor

Supports compiling introspection queries/fields:

  • query { __schema }
  • query { __type(name: "Name") }
  • __typename on any field.

@josephsavona
Copy link
Contributor Author

addresses #268 #162

@josephsavona
Copy link
Contributor Author

cc @devknoll @drabinowitz

@devknoll
Copy link
Contributor

👍

Daydreaming a little bit, it might be nice if the sort of thing in #268 could be baked into Relay (or a Relay add-on) in some capacity in a way that prevents developer errors. I'm imagining something like:

post {
  fragment on Post {
    ${Video.getFragment('video')},
    ${Picture.getFragment('picture')}
  }
}

(notice that there's no explicit __typename query)

Instead, a developer would just do something like:

const Component = this.props.relay.matchFragmentType(this.props.post, {
  'Video': () => Video,
  'Picture': () => Picture,
});

Now the babel plugin could find any calls to matchFragmentType and automatically insert __typename as appropriate. There would be an invariant thrown if a key passed in does not match one of the possible types, and a warning if there is some type that is not handled (and perhaps a default key or parameter added to handle/silence that case).

Thoughts?

@josephsavona
Copy link
Contributor Author

@devknoll interesting. can you file an issue to discuss the idea?

@josephsavona josephsavona force-pushed the compile-introspection-fields branch from add0266 to 11d2508 Compare September 10, 2015 20:30
josephsavona added a commit that referenced this pull request Sep 18, 2015
Summary: Supports compiling introspection queries/fields:
- `query { __schema }`
- `query { __type(name: "Name") }`
- `__typename` on any field.
Closes #280

Reviewed By: @yungsters

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

Successfully merging this pull request may close these issues.

3 participants