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
Implement subscription #94
Conversation
As per #74 (comment), we have one failing test I don't know what is wrong:
cc @ruiaraujo |
@hoangvvo apologies for not reacting earlier. Do you plan to finish this PR? |
Hey, no worry. I do plan to finish the PR. I will get back to this once I have a chance sometimes later this week. |
@ruiaraujo For the failing test, if I use
It seems like The relevant code is at Line 1762 in 7937b3b
|
); | ||
|
||
const functionBody = compileOperation(context, type, fieldMap); | ||
|
||
const compiledQuery: InternalCompiledQuery = { |
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 is not supposed to be there in case of subscriptions, right?
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.
compiledQuery.query()
will still be there. It will be used in mapSourceToResponse
function similar to the way graphql-js
uses execute
. (with rootValue
being the source)
https://github.com/graphql/graphql-js/blob/main/src/subscription/subscribe.js#L143
Is there anything I can do to push this forward? Thanks. |
Can you fix the build, we can get it in and then iterate on the API if needed. |
I made the change to bump it back up. Builds are passing now. |
👍 |
@boopathi please take a look, I intend to merge this as is and iterate on the API if needed. |
I was trying it locally with GraphQL-Tools' The source code for this test is available here in this gist - https://gist.github.com/boopathi/885f41720f258b50a2ba67bed76581af The resolver is highlighted in the gist. Is it possible to not specify this resolver explicitly? |
const mapSourceToResponse = (payload: any) => | ||
queryFn(payload, executionContext.context, executionContext.variables); | ||
|
||
return mapAsyncIterator( |
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.
Probably an unimportant issue - the arguments to the next()
fn in the async iterator is ignored in the implementation of the function mapAsyncIterator
-
I was trying to pass back a value from the GraphQL subscription result to the async generator function -
// implementation
async *subscribe() {
let previousValue = initialValue ?? previousValueFromInput;
for (;;) {
previousValue = yield promise(previousValue);
}
}
// usage
const sub = await subscribe(`subscription { value }`);
const firstValue = await sub.next(
something, client, wants, to, send, during, iteration /* These arguments are ignored */
);
This is probably a GraphQL-JS bug, I'm just curious if there are no usages of this pattern. We do not have to resolve this comment in this PR.
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 is indeed a valid pattern. Perhaps we can implement our own version of mapAsyncIterator (maybe we should either way because mapAsyncIterator
is "internal"-ish for graphql-js? Maybe we can do it in a different PR
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.
Yup mapAsyncIterator was changed to named export:
https://github.com/APIs-guru/graphql-js/blob/28315cd3f51b5ac212284f8583fb481053fa31a0/src/subscription/mapAsyncIterator.js graphql/graphql-js#2916
We should implement our own to avoid breaking changes like thi
not graphql-tools, even if I create a schema with GraphQLSchema but not setting the identity function, graphql-js fails: |
Odd because in |
I am closing this in favor of #115. |
This implements subscription support via
jit.subscribe
.Close #74