delegateToSchema is not using my executor

372 views Asked by At

I want to delegate a field from my graphql service to a remote service. I tried to follow the docs, but I'm missing something.

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 result = await delegateToSchema({
    schema: await makeRemoteSchema(),
    operation: 'query',
    fieldName: 'conversations',
    args: {
      consultationParticipantId: id,
    },
    context,
    info
  });
  return result;
};

The result is null. I can see that it's using my executor to make the introspection call, by when resolving the field it's using the default executor instead, which is basically a no-op. By stepping through the delegateToSchema code it seems like it wants schema to be a schemaConfig. So I tried removing wrapSchema like so:

const makeRemoteSchema = async () => {
  return {
    schema: await introspectSchema(executor),
    executor
  };
}

It uses my executor and not the default, but now in the executor, query is resolved as empty string an variables is an empty object.

Can you see what I'm doing wrong?

I'm using:

"graphql-tools": "^7.0.4",
"@graphql-tools/wrap": "^7.0.8",

I also tried v6.2.4.

0

There are 0 answers