Skip to content

Update Learn-Schema.md -- Improve Union Type Examples #635

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

Merged
merged 2 commits into from
Jan 3, 2019

Conversation

knpwrs
Copy link
Contributor

@knpwrs knpwrs commented Jan 1, 2019

This PR adds __typename to the query to show that union types can still be differentiated on the client and adds a second example showing common fields being queried in one spot.

There is another way to accomplish the same thing that I pointed out in this PR using fragments. Ultimately I felt like the solution targeting the common interface was cleaner and adding a note about Fragments might feel cluttered, but we can add this example if desired as well:

{
  search(text: "an") {
    __typename
    ... on Human {
      ...CharacterProps
      height
    }
    ... on Droid {
      ...CharacterProps
      primaryFunction
    }
    ... on Starship {
      name
      length
    }
  }
}

fragment CharacterProps on Character {
  name
}

Add `__typename` to the query to show that union types can still be differentiated on the client and add a second example showing common fields being queried in one spot.
@@ -311,6 +311,7 @@ In this case, if you query a field that returns the `SearchResult` union type, y
# { "graphiql": true}
{
search(text: "an") {
__typename
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add something to the text regarding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stubailo That should be all set now.

@stubailo
Copy link
Contributor

stubailo commented Jan 3, 2019

Thanks!

@stubailo stubailo merged commit c0cc5e1 into graphql:source Jan 3, 2019
@knpwrs knpwrs deleted the patch-1 branch January 4, 2019 00:29
Dipeshwagle pushed a commit to Dipeshwagle/graphql.github.io that referenced this pull request Aug 18, 2020
* Update Learn-Schema.md

Add `__typename` to the query to show that union types can still be differentiated on the client and add a second example showing common fields being queried in one spot.

* Add note about the use of `__typename`
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

Successfully merging this pull request may close these issues.

3 participants