ardatan/graphql-toolkit

Change loadSchema architecture and make it easier to load schemas?

Closed this issue · 0 comments

At the moment, we support multiple inputs, and load the schema out of it. But in case of schema that written in .graphql AND .ts files, it won't work.

I think we need to have the following:

  • loadSchema should accept a string, which is either a glob expression (for multiple files, or a single file) or a path string, url with AST.
  • If the string is AST, we should build it and return DocumentNode.
  • If the string is url, we should introspect it, build it and return DocumentNode.
  • If the string is a glob path, we should execute the glob, and then per each found file, we need to apply the chain-of-responsibility to load from it, in that order: first, try to guess the file according to the extension, then try to load is using require and look for the exported schema or default, otherwise, try to load the file as string, and use graphql-tag-pluck to extract content out of it.
  • Then, all the found types from all files should be merged and exported.