apollographql/apollo-link

[apollo-link-schema] should apollo-link-schema allow context arg to be async?

Opened this issue · 1 comments

hrgui commented

Expected Behavior
Expected context arg in SchemaLink from apollo-link-schema to allow async (e.g. returning a promise)

Wanted to mirror this functionality: https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/ApolloServer.ts#L732-L743. Apollo Server allows context to be async because of these lines.

Actual Behavior
context arg does not allow promises as a return. Workaround is to await context in respective resolvers (Workaround 1), or override SchemaLink.request (Workaround 2)

A simple reproduction

Expect: Hello User ${number}!
Actual: Hello !

Repro: https://codesandbox.io/s/apollo-link-schema-context-broken-kjk0i
Workaround 1: https://codesandbox.io/s/apollo-link-schema-context-workaround-t38hc
Workaround 2: https://codesandbox.io/s/apollo-link-schema-context-workaround-2-fhiyg (See ExtSchemaLink.js as a possible solution?)

Just got bit by the same issue when I made my context creator function async and (after much debugging) discovered that SchemaLink wasn't resolving the promise before passing it to resolvers. This is pretty surprising behaviour to me!