Skip to content

gateway: Update gateway.load() to support AS2 and AS3 #819

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 1 commit into from
Jun 16, 2021

Conversation

glasser
Copy link
Member

@glasser glasser commented Jun 16, 2021

Starting with AS 2.25.0, gateway.load receives graphRef in addition to
graphId and graphVariant; graphVariant is declared as always
provided.

In AS3, only graphRef will be provided; graphVariant will not be
provided.

In order for this code to work with both versions, we declare a version
of ApolloConfig that could come from either ourselves, and parse it into
an internal representation based on the AS3 version.

Starting with AS 2.25.0, gateway.load receives `graphRef` in addition to
`graphId` and `graphVariant`; `graphVariant` is declared as always
provided.

In AS3, only `graphRef` will be provided; `graphVariant` will not be
provided.

In order for this code to work with both versions, we declare a version
of ApolloConfig that could come from either ourselves, and parse it into
an internal representation based on the AS3 version.
@glasser glasser force-pushed the glasser/as3-compat branch from 93bc8c9 to ff9f07d Compare June 16, 2021 16:53
Copy link
Contributor

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

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

Wondering if we should keep at least one test around that implements the "legacy" config and mark it as such?

Comment on lines +111 to +116
// The protocol for talking to GCS requires us to split the graph ref
// into ID and variant; sigh.
const at = graphRef.indexOf('@');
const graphId = at === -1 ? graphRef : graphRef.substring(0, at);
const graphVariant = at === -1 ? 'current' : graphRef.substring(at + 1);

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The protocol for talking to GCS requires us to split the graph ref
// into ID and variant; sigh.
const at = graphRef.indexOf('@');
const graphId = at === -1 ? graphRef : graphRef.substring(0, at);
const graphVariant = at === -1 ? 'current' : graphRef.substring(at + 1);
// The protocol for talking to GCS requires us to split the graph ref
// into ID and variant; sigh.
const [graphId, graphVariant = "current"] = graphRef.split("@");

Copy link
Member Author

Choose a reason for hiding this comment

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

That's cool syntax I hadn't thought of. But if there are multiple @s it just silently drops whatever is after the second, right? Not really legal variant but still. (Super messed up that the limit arg to JS string.split isn't "stop splitting after N pieces" but "throw away all bit the first N pieces".)

@glasser
Copy link
Member Author

glasser commented Jun 16, 2021

I think the legacyNetworkRequests tests test the old "pass in graphId/graphVariant" way reasonably well, though they aren't explicitly called out like a unit test of it.

@glasser glasser merged commit febd062 into main Jun 16, 2021
@glasser glasser deleted the glasser/as3-compat branch June 16, 2021 19:08
glasser added a commit that referenced this pull request Jun 16, 2021
GraphQLServiceEngineConfig is being removed in AS3, so we can't import
it and use it in our public API if we want to work with both AS2 and
AS3.
glasser added a commit that referenced this pull request Jun 16, 2021
GraphQLServiceEngineConfig is being removed in AS3, so we can't import
it and use it in our public API if we want to work with both AS2 and
AS3.
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.

2 participants