-
Notifications
You must be signed in to change notification settings - Fork 259
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
Conversation
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.
93bc8c9
to
ff9f07d
Compare
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.
Wondering if we should keep at least one test around that implements the "legacy" config and mark it as such?
// 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); | ||
|
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.
// 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("@"); |
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'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".)
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. |
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.
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.
Starting with AS 2.25.0, gateway.load receives
graphRef
in addition tographId
andgraphVariant
;graphVariant
is declared as alwaysprovided.
In AS3, only
graphRef
will be provided;graphVariant
will not beprovided.
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.