-
I want to delegate resolution of a field on a local schema to a remote schema. It seems like a simple use case, and I tried to follow the docs. But apparently I'm doing something wrong. Here's my code: const {wrapSchema, introspectSchema} = require('@graphql-tools/wrap');
const got = require('got');
const {print} = require('graphql');
const {delegateToSchema} = require('graphql-tools');
const executor = async({document, variables}) => {
const query = typeof document === 'string' ? document : print(document);
return got.post('http://localhost:6677/graphql', {json: {query, variables}}).json();
};
const makeRemoteSchema = async () => {
return wrapSchema({
schema: await introspectSchema(executor),
executor
});
};
const conversations = async ({id}, _, context, info) => {
const messageIndexSchema = await makeRemoteSchema();
const result = await delegateToSchema({
schema: messageIndexSchema,
operation: 'query',
fieldName: 'conversations',
args: {
consultationParticipantId: id,
},
context,
info
});
return result;
};
Now it does use my executor, but in the executor, but the Can you see what I'm doing wrong? Thanks for the help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You don't need to wrap the schema, it will add another delegation round. You can return the subschema directly; const { introspectSchema} = require('@graphql-tools/wrap');
const got = require('got');
const {print} = require('graphql');
const {delegateToSchema} = require('graphql-tools');
const executor = async({document, variables}) => {
const query = typeof document === 'string' ? document : print(document);
return got.post('http://localhost:6677/graphql', {json: {query, variables}}).json();
};
const makeRemoteSchema = async () => {
return {
schema: await introspectSchema(executor),
executor };
};
const conversations = async ({id}, _, context, info) => {
const messageIndexSchema = await makeRemoteSchema();
const result = await delegateToSchema({
schema: messageIndexSchema,
operation: 'query',
fieldName: 'conversations',
args: {
consultationParticipantId: id,
},
context,
info
});
return result;
}; |
Beta Was this translation helpful? Give feedback.
-
Fixed. I had both the fieldName and the argname wrong. If you get this kind of error, double check that. |
Beta Was this translation helpful? Give feedback.
Fixed. I had both the fieldName and the argname wrong. If you get this kind of error, double check that.