mercurius-js / mercurius-federation

Build federated schema to be allow the service to be used in mercurius federation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support to graphql-tag

codeflyer opened this issue · comments

Allow to pass a DocumentNode created by graphql-tag to the buildFederationSchema

export declare const buildFederationSchema: (
  schema: string | DocumentNode,
  opts?: buildFederationSchemaOptions
) => GraphQLSchema

Example

const gql = require('graphql-tag')

const schema = gql`
  extend type Query {
    me: User
  }

  type User @key(fields: "id") {
    id: ID!
    name: String
    username: String
  }
`

Why is this an important feature?

To integrate tools that help to organise the project

(Eg.)

    const {loadFiles} = require('@graphql-tools/load-files')
    
    const schema = await loadFiles(
      path.resolve(__dirname, '../modules/**/*.graphql')
    )

    const resolvers = (await loadFiles(
      path.resolve(__dirname, '../modules/**/resolvers.js')
    )).reduce((acc, resolver) => {
      Object.entries(resolver).forEach(([key, value]) => {
        if(!acc[key]) {
          acc[key] = {}
        }

        acc[key] = {...acc[key], ...value}
      })

      return acc
    }, {})

Maybe all this automation can be added in a separated module to manage mercurius modules (https://github.com/mercurius-js/mercurius-modules)