-
Notifications
You must be signed in to change notification settings - Fork 10
Union type check #41
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
Union type check #41
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
81b820d
union type check
miwialex ba31ac1
Use IntrospectionFragmentMatcher in dummy app
9d25c9c
Add eq helper to dummy app
9a33c8e
Add acceptance test for union type handling
94a0afa
Switch apollo service to classic ember class
721a989
Add ember-native-class-polyfill in dev
5c64d85
Upgrade version of ember-apollo-client
591238c
Use latest ember-apollo-client best practises
dc4d11c
Quotes 🤦♀️
7e75372
Drop support for Ember < 3.12
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { module, test } from 'qunit'; | ||
| import { setupApplicationTest } from 'ember-qunit'; | ||
| import { visit } from '@ember/test-helpers'; | ||
|
|
||
| module('Acceptance | union', function(hooks) { | ||
| setupApplicationTest(hooks); | ||
|
|
||
| test('it is able to resolve union types', async function(assert) { | ||
| let person = this.server.create('person', { | ||
| firstName: 'Alice', | ||
| lastName: 'Example', | ||
| age: 30 | ||
| }); | ||
| let pet = this.server.create('animal', { | ||
| name: 'Beanie', | ||
| age: 10 | ||
| }); | ||
|
|
||
| await visit('/pets-and-people'); | ||
|
|
||
| assert | ||
| .dom('.pet-id') | ||
| .containsText(pet.id); | ||
| assert | ||
| .dom('.pet-name') | ||
| .containsText(pet.name); | ||
| assert | ||
| .dom('.pet-age') | ||
| .containsText(pet.age); | ||
| assert | ||
| .dom('.person-id') | ||
| .containsText(person.id); | ||
| assert | ||
| .dom('.person-name') | ||
| .containsText(`${person.firstName} ${person.lastName}`); | ||
| assert | ||
| .dom('.person-age') | ||
| .containsText(person.age); | ||
| }) | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| query { | ||
| petsAndPeople { | ||
| ... on Pet { | ||
| id | ||
| age | ||
| name | ||
| } | ||
| ... on Person { | ||
| id | ||
| age | ||
| firstName | ||
| lastName | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { helper } from '@ember/component/helper'; | ||
|
|
||
| export default helper(([a, b]) => a === b); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import Route from '@ember/routing/route'; | ||
| import query from 'dummy/gql/queries/pets-and-people'; | ||
| import { queryManager } from 'ember-apollo-client'; | ||
|
|
||
| export default Route.extend({ | ||
| apollo: queryManager(), | ||
|
|
||
| model() { | ||
| const apollo = this.get('apollo'); | ||
| return apollo.watchQuery({ query }); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import ApolloService from 'ember-apollo-client/services/apollo'; | ||
|
jneurock marked this conversation as resolved.
|
||
| import { | ||
| IntrospectionFragmentMatcher, | ||
| InMemoryCache | ||
| } from 'apollo-cache-inmemory'; | ||
| import schema from 'dummy/gql/schema'; | ||
| const unionTypes = schema.definitions.filter(d => d.kind === 'UnionTypeDefinition'); | ||
| const introspectionQueryResultData = { | ||
| __schema: { | ||
| types: unionTypes.map(t => ({ | ||
| kind: 'UNION', | ||
| name: t.name.value, | ||
| possibleTypes: t.types.map(t => ({ name: t.name.value })) | ||
| })) | ||
| } | ||
| }; | ||
|
|
||
| export default class extends ApolloService { | ||
| cache() { | ||
| const fragmentMatcher = new IntrospectionFragmentMatcher({ | ||
| introspectionQueryResultData | ||
| }); | ||
|
|
||
| return new InMemoryCache({ fragmentMatcher }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| {{#each model.petsAndPeople as |p|}} | ||
| {{#if (eq p.__typename "Pet")}} | ||
| <div class="pet-id">{{p.id}}</div> | ||
| <div class="pet-name">{{p.name}}</div> | ||
| <div class="pet-age">{{p.age}}</div> | ||
| {{else}} | ||
| <div class="person-id">{{p.id}}</div> | ||
| <div class="person-name">{{p.firstName}} {{p.lastName}}</div> | ||
| <div class="person-age">{{p.age}}</div> | ||
| {{/if}} | ||
| {{/each}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be an edge case, but would there be an issue if multiple types had the same
fieldNamebut the fields were different types?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be an issue but addressing it seems like a much larger piece of work that can potentially come later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this would be an issue. I feel the appropriate thing would be to add full UnionType functionality at that point, where this is a simple fix that allows us to add UnionTypes and use mapping to accomplish it