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
Subscriptions not working if using RenameRootFields #997
Comments
Any help? |
please... |
Same Problem here… When the This is my example code, which didn't work: import { PubSub } from 'apollo-server';
import gql from 'graphql-tag';
import { makeExecutableSchema, RenameRootFields, transformSchema } from 'graphql-tools';
const pubsub = new PubSub();
const COUNTER_INCREMENT_TOPIC = 'counter_increment';
let counter = 0;
setInterval(() => {
pubsub.publish(COUNTER_INCREMENT_TOPIC, { counterIncrement: { value: counter += 1 } });
}, 1000);
const resolvers = {
Subscription: {
counterIncrement: {
subscribe: () => pubsub.asyncIterator(COUNTER_INCREMENT_TOPIC),
},
},
Query: {
currentCount: () => ({ value: counter }),
},
};
const typeDefs = gql`
type CounterValue {
value: Int!
}
type Subscription {
counterIncrement: CounterValue
}
type Query {
currentCount: CounterValue
}
`;
const schema = transformSchema(
makeExecutableSchema({ typeDefs, resolvers }),
[
new RenameRootFields((_operation, name) => `prefix_${name}`),
// new RenameRootFields((_operation, name) => name), // will work
],
); |
Make sure your AsyncIterator resolves to the renamed field, as no internals are taking care of that:
EDIT: Curious as I am and with similar use cases, I recreated the example from @micha149 here https://github.com/kommander/graphql-tool-repro/tree/renamed-field-subscriptions. The transforms break the resolvers, returning null, about here https://github.com/apollographql/graphql-tools/blob/master/src/transforms/transformSchema.ts#L15-L28. So much magic. ANOTHER EDIT: So the problem seems to be that the |
I tried to fix this in PR #1036 |
My guess is that this more generally results from the fact that each subscription payload is mapped over the normal GraphQl When schemas are merged, the mergedSchema receives a subscription payload from the target schema and passes it back, setting up another round of this resolution. For this reason, Currently, the wrapping is hard-coded with the subscriptionKey from the targetSchema, this should probably be transformed at this point to cover all edge cases, or the flow should be overall adjusted. |
Seems as easy as wrapping the payload with |
Is there an update on a fix for this? |
Fixed in graphql-tools-fork https://www.npmjs.com/package/graphql-tools-fork |
We recently released an alpha version of GraphQL Tools (#1308) that should fix the issue. Please update
Let us know if it solves the problem, we're counting for your feedback! :) |
Rolled into #1306 |
Subscriptions not working if using RenameRootFields and schema stiching.
Example:
GraphQL subscription:
An error:
The text was updated successfully, but these errors were encountered: