Repository: mercurius-js/mercurius (js)

Issue:
Better error messages on passing array of executable schemas.
In Mercurius' schema option, we can pass schemas as either a string or an executable schema. 

If we pass them as a string, we can also pass an array of schemas in the string type, in which case Mercurius will merge them. 

However, if we pass them as an executable schema, we can only pass one. 
Currently, there is no check to prevent the passing of an array of executable schemas. 
If we pass two executable schemas, we get an error.

Possible solutions:

- improve error handling
- use schema stitching against the executable schemas to get just one executable schema

https://github.com/mercurius-js/mercurius/blob/b6ac05724b7715ba90d8686aa8218fc8de10ffd1/index.js#L148-L171

Pull request description:
schema option: Better error handling when providing arrays with non-string schemas
closes #984 

Patch:
diff --git a/index.js b/index.js
index 171b7fa..d97b454 100644
--- a/index.js
+++ b/index.js
@@ -148,6 +148,10 @@ const plugin = fp(async function (app, opts) {
   let schema = opts.schema
 
   if (Array.isArray(schema)) {
+    if (schema.some(s => typeof s !== 'string')) {
+      throw new MER_ERR_INVALID_OPTS('when providing an array to the "schema" option, only string schemas are allowed')
+    }
+
     schema = schema.join('\n')
   }
 


Test patch:
diff --git a/test/app-decorator.js b/test/app-decorator.js
index dded089..4c0f146 100644
--- a/test/app-decorator.js
+++ b/test/app-decorator.js
@@ -1075,6 +1075,29 @@ test('extended Schema is an object', async t => {
   await app.ready()
 })
 
+test('array of schemas contains a non-string schema', async t => {
+  const app = Fastify()
+
+  app.register(GQL, {
+    schema: [makeExecutableSchema({
+      typeDefs: `
+          type Query {
+            add(x: Int, y: Int): Int
+          }
+        `,
+      resolvers: {
+        Query: {
+          add: async (_, { x, y }) => x + y
+        }
+      }
+    })]
+  })
+
+  await t.rejects(app.ready(), {
+    message: 'Invalid options: when providing an array to the "schema" option, only string schemas are allowed'
+  })
+})
+
 test('Error in schema', async (t) => {
   const schema = `
     interface Event {