Ivan Asmer 5 år sedan
förälder
incheckning
ff49b112c4
1 ändrade filer med 6 tillägg och 3 borttagningar
  1. 6 3
      index.js

+ 6 - 3
index.js

@@ -212,15 +212,17 @@ const anonResolvers = ['login', 'createUser'];
             }
         }
         const operationMatch = gql.query.match(/\{\s*([a-zA-Z]+)\s*/)
-        const operationName  = operationMatch[1]
-        const authorization = req.headers.authorization 
-        if (operationName === null || anonResolvers.includes(operationName)){
+        const operationName  = gql.operationName || operationMatch[1]
+        console.log('before oper', operationName, operationMatch)
+        if ((!operationName) || anonResolvers.includes(operationName)){
             return {
                 schema: schema,
                 rootValue: rootResolvers,
                 graphiql: true, 
             }
         }
+        const authorization = req.headers.authorization 
+        console.log(authorization)
         
         if (authorization && authorization.startsWith('Bearer ')){
             console.log('token provided')
@@ -240,6 +242,7 @@ const anonResolvers = ['login', 'createUser'];
                 }
             }
         }
+        console.log('bad end')
     }))