棱镜继电器连接通过

时间:2019-06-30 06:12:55

标签: node.js graphql prisma prisma-graphql

我有一个基本的graphql-yoga服务器,该服务器将一个字段传递到棱柱形中继连接。出于某种原因,即使所有其他字段都可以正常运行,聚合属性也表明我未被授权。我也可以从prisma的游乐场打电话给聚合。

index.ts

const server = new GraphQLServer({
  schema,
  middlewares: [permissions],
  context: request => {
    return {
      ...request,
      prisma,
    }
  },
})

server.start(() => console.log(`? Server ready at http://localhost:4000`))

权限/index.ts

import { rule, shield } from 'graphql-shield'
import { getUserId } from '../utils'

const rules = {
  isAuthenticatedUser: rule()((parent, args, context) => {
    const userId = getUserId(context)
    return Boolean(userId)
  }),
  isPostOwner: rule()(async (parent, { id }, context) => {
    const userId = getUserId(context)
    const author = await context.prisma.post({ id }).author()
    return userId === author.id
  }),
}

export const permissions = shield({
  Query: {
    me: rules.isAuthenticatedUser,
    filterPosts: rules.isAuthenticatedUser,
    post: rules.isAuthenticatedUser,
  },
  Mutation: {
    createDraft: rules.isAuthenticatedUser,
    deletePost: rules.isPostOwner,
    publish: rules.isPostOwner,
  },
})

解析器/Query.ts

export const Query = prismaObjectType({
  name: 'Query',
  t.prismaFields(['postsConnection'])
});
  

错误:未经授权!       在normalizeOptions(C:\ project \ server \ node_modules \ graphql-shield \ src \ shield.ts:32:32)

at Object.shield (C:\project\server\node_modules\graphql-shield\src\shield.ts:51:29)   

at Object.<anonymous> (C:\project\server\src\permissions\index.ts:16:28)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Module._compile (C:\project\server\node_modules\source-map-support\source-map-support.js:521:25)
at Module.m._compile (C:\Users\me\AppData\Local\Temp\ts-node-dev-hook-8773075548230125.js:56:25)
at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at require.extensions.(anonymous function) (C:\Users\me\AppData\Local\Temp\ts-node-dev-hook-8773075548230125.js:58:14)
at Object.nodeDevHook [as .ts] (C:\project\server\node_modules\ts-node-dev\lib\hook.js:61:7)    at
     

Module.load(内部/模块/cjs/loader.js:653:32)

0 个答案:

没有答案