Ivan Asmer 5 years ago
parent
commit
ca8f4f9385
1 changed files with 4 additions and 1 deletions
  1. 4 1
      index.js

+ 4 - 1
index.js

@@ -386,13 +386,16 @@ const anonResolvers = ['login', 'createUser'];
     }
 
     app.use('/graphql', express_graphql(async (req, res, gql) => { 
+        const operationMatch = gql.query.match(/\{\s*([a-zA-Z]+)\s*/)
+        const operationName  = operationMatch[1]
         const authorization = req.headers.authorization 
-        if (!authorization && (gql.operationName === null || anonResolvers.includes(gql.operationName)))
+        if (operationName === null || anonResolvers.includes(operationName)){
             return {
                 schema: schema,
                 rootValue: rootResolvers,
                 graphiql: true, 
             }
+        }
         
         if (authorization && authorization.startsWith('Bearer ')){
             console.log('token provided')