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

Updated interface support #121

Merged
merged 1 commit into from
Mar 6, 2019
Merged

Conversation

rebeccajfriedman
Copy link
Contributor

Adds support for falling back when interface objects can't be translated.
Relates to Shopify/js-buy-sdk#614

I'm trying to fix the situation in the linked issue, which is outlined below:

  • The GraphQL schema has an interface type (DiscountApplication)
  • There is a new implementation type on the server (AutomaticDiscountApplication)
  • The schema is updated in a new client version.
  • The server starts returning AutomaticDiscountApplication objects to an old version of the client, which does not have a definition for it in the schema. Instead of failing silently / falling back, the query
    returns an error.

src/decode.js Outdated
@@ -116,11 +116,13 @@ function transformScalars(context, value) {
}

function recordTypeInformation(context, value) {
const selectionSet = context.selection.selectionSet;
Copy link
Contributor

@melissaluu melissaluu Mar 6, 2019

Choose a reason for hiding this comment

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

Just for reference, you can also destructure the context.selection.selectionSet like this:

const {typeBundle, typeSchema} = context.selection.selectionSet;

This way you can directly use the typeBundle and typeSchema constants afterwards.

@@ -3,6 +3,7 @@ import typeBundle from '../fixtures/custom-type-bundle';
import schemaForType from '../src/schema-for-type';
import Query from '../src/query';
import Mutation from '../src/mutation';
import realTypeBundle from '../fixtures/types'; // eslint-disable-line import/no-unresolved
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm unsure about the naming here. It may be better to call typeBundle customTypeBundleand this onetypeBundleor something.realTypeBundle` just raises all sorts of questions about what the other bundle is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're completely right. I will rename this.

Copy link
Contributor

@minasmart minasmart left a comment

Choose a reason for hiding this comment

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

Just one small potential naming change. This is great otherwise tho. Thanks for digging through this project and getting this change in 🙌🏻

Copy link
Contributor

@melissaluu melissaluu left a comment

Choose a reason for hiding this comment

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

LGTM 👍

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.

None yet

4 participants