Circular Ref Error while useServer generates context on 'onConnect' #360
-
Expected Behaviour Actual Behaviour Debug Information Further Information
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
BTW, I'm using this library with Apollo 3, and my old approach did work flawlessly with old suggested method (subscription-transport-ws) |
Beta Was this translation helpful? Give feedback.
-
Object value returned from I guess you want to create a GraphQL operation context, for that you should use the this.serverCleanup = useServer(
{
schema,
- onConnect: async (connectionContext) => {
- const { connectionParams, extra } = connectionContext;
- this.log.info("CONNECTED");
- const context = await this.context(null, connectionParams);
- await this.clientDidConnect(connectionParams, extra.socket, context);
-
- return context // <<< here my context generation method, generates all models, integrations etc. and return as one big object
- },
+ onConnect: async (connectionContext) => {
+ const { connectionParams, extra } = connectionContext;
+ this.log.info("CONNECTED");
+ await this.clientDidConnect(connectionParams, extra.socket, context);
+ },
+ context: async (connectionContext) => {
+ const { connectionParams, extra } = connectionContext;
+ return await this.context(null, connectionParams);
+ },
onDisconnect: async (connectionContext) => {
const { connectionInitReceived, extra } = connectionContext;
if (connectionInitReceived) {
this.log.info("DISCONNECTED");
const context = await connectionInitReceived; // <<< not related to this issue but I also want to generate ctx here,
this approach did work with old impl. subscription-transport-ws
await this.clientDidDisconnect(extra.socket, connectionContext, context);
}
},
},
this.wsServer,
); |
Beta Was this translation helpful? Give feedback.
Object value returned from
onConnect
is theConnectionAck
payload that gets sent to the client, it must be JSON stringified (see documentation foronConnect
).I guess you want to create a GraphQL operation context, for that you should use the
context
server option instead.