Skip to content
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

Issue with Types when stitching schema #1

Closed
tvvignesh opened this issue Nov 27, 2020 · 5 comments
Closed

Issue with Types when stitching schema #1

tvvignesh opened this issue Nov 27, 2020 · 5 comments

Comments

@tvvignesh
Copy link

Hi. I tried doing fetchRemoteSDL and retrieving the SDL from the remote service instead of doing introspection as mentioned here: https://github.com/gmac/schema-stitching-demos/blob/master/01-combining-local-and-remote-schemas/index.js#L30 and it worked well.

But there was a typings issue as below:

1

where the object is nothing but same as in the example:

return {
    schema: buildSchema(remoteSchema),
    executor: httpExecutor
  };

Currently, working around this by adding a ts-ignore like this:

subschemas: [
      // @ts-ignore
      {
        schema: authService.schema,
        executor: authService.executor
      }
]

Thanks.

CC: @gmac

@gmac
Copy link
Owner

gmac commented Nov 27, 2020

I guess I don’t follow the problem here. Looks like you haven’t converted the example into typescript, which I assume you are using? These examples are plain JavaScript. You’d need to add casting information as appropriate to your version of TypeScript. I’m intentionally using JavaScript as a lowest-common denominator.

Please let me know if I’m missing something else here that is technically inaccurate in the example.

@tvvignesh
Copy link
Author

@gmac Thanks for the clarification. I assumed that it was compatible with Typescript out of the box. Will fix it on my end then 👍

@tvvignesh
Copy link
Author

@gmac Btw, I just had to mark the return type as AsyncExecutor and the error above went away 🎉

import { AsyncExecutor } from '@graphql-tools/delegate';

const makeRemoteExecutor = function(url:string) : AsyncExecutor {
  return async ({ document, variables }) => {
    const query = typeof document === 'string' ? document : print(document);
    const fetchResult = await fetch(url, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        query, variables
      })
    });
    return fetchResult.json();
  };
};

@gmac
Copy link
Owner

gmac commented Nov 27, 2020

Sounds about right! Is Stitching starting to make more sense now with some concrete examples? I personally find it to be fairly intuitive given that the subservices are all plain GraphQL, versus Federation where there’s a bunch of magic happening at every layer of the stack to bring it all together.

@tvvignesh
Copy link
Author

@gmac Stitching - Yes, Typemerging - In Progress . While I understood the concepts properly with both of ur help and have it setup as part of the stack, I am working to see how I can fit it for my usecases. Will share my progress as I go along.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants