【问题标题】:Replicate graphQL introspection query with a regular GraphQL query to avoid security risk (whilst using graphql-compose-mongoose)使用常规 GraphQL 查询复制 graphQL 自省查询以避免安全风险(同时使用 graphql-compose-mongoose)
【发布时间】:2019-06-21 02:51:52
【问题描述】:

尝试从 graphQL 查询中取回 IdTypes 列表。目前使用自省来获取列表,但是在安全审核之后,我们被建议禁用自省。

这是我目前得到的,显然它不起作用:(

import mongoose from 'mongoose'
import { GQC } from 'graphql-compose';
import { composeWithMongoose } from 'graphql-compose-mongoose';

export const IdTypeSchema = new mongoose.Schema({
  idType: {
    type: String,
    enum: ['ID', 'Passport', 'None']
  }
})

const IdType = mongoose.model('IdType', IdTypeSchema)

export const IdTypeTC = composeWithMongoose(IdType, {})

GQC.rootQuery().addFields({
  idTypesMany: IdTypeTC.getResolver('findMany')
})

枚举不太可能经常更改。

【问题讨论】:

    标签: graphql introspection graphql-compose-mongoose


    【解决方案1】:

    我没有解决这个问题 - 但这是有效的:D 根本不需要猫鼬……

    import { GQC, Resolver } from 'graphql-compose'
    import { validateSession } from '../authentication'
    import { ID_TYPES } from './constants'
    
    export function _idTypeResolveHandler () {
      return ID_TYPES
    }
    
    const idTypeResolver = new Resolver({
      name: 'getIdTypes',
      type: ['String'],
      resolve: _idTypeResolveHandler
    })
    
    GQC.rootQuery().addFields({
      idTypes: idTypeResolver
        .wrapResolve(next => resolveParams => {
          const { user } = resolveParams.context.state
          return next(resolveParams)
        })
    })
    

    【讨论】:

      猜你喜欢
      • 2020-03-05
      • 2020-07-15
      • 2020-04-17
      • 1970-01-01
      • 2021-05-18
      • 2019-04-02
      • 2019-04-16
      • 2021-08-26
      • 2022-01-21
      相关资源
      最近更新 更多