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

Add support to graphql-tag #4

Open
codeflyer opened this issue Nov 12, 2022 · 0 comments
Open

Add support to graphql-tag #4

codeflyer opened this issue Nov 12, 2022 · 0 comments

Comments

@codeflyer
Copy link
Collaborator

codeflyer commented Nov 12, 2022

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)

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

1 participant