GraphQL中的动态类型

问题描述 投票:0回答:1
const typeDef = `

  type User {
    id: ID!
    name: String!
    email: String!
  }
  type Post { 
    id: ID!
    title: String!
    content: String!
  }
  extend type Query {
    getDocuments(collection: String!): [User] || [Post]     // <<<<< Here!
  }   
`

是否可以同时将getDocuments类型定义为[User][Post]?我有几个数据集合(用户,帖子,付款等),我想定义一个getter getDocuments来获取数据以减少重复的代码。

// like this

getDocuments(collection: 'User')
getDocuments(collection: 'Post')
graphql react-apollo
1个回答
0
投票

Graphql是强类型的。我认为这是不可能的。如果必须的话,您可以考虑使用标量类型,例如JSON。

© www.soinside.com 2019 - 2024. All rights reserved.