如何在GraphQL对象中组合多个字段

时间:2019-06-17 12:18:39

标签: graphql

我正在尝试我的第一个Graphql Schema设计。对象类型内的单个字段是否可能引用复杂的对象?

enum KeyPrefix {                                                                                      
    WS                                                                                 
    WK                                                                                   
    SI                                                                                          
    ENT                                                                                                                                                      
}                                                                                                     

input generalKey {                                                                                    
    keyPrefix:KeyPrefix!                                                                              
    key:Int!                                                                                          
}                                                                                                     

type Item                                
{                                                                                                     
    pk: generalKey!                                                                                                                                                                              
    data: String!                                                                                     
    name: String!                                                                                     
}   

它给我以下错误。 Item.pk的类型必须为Output Type,但得到:generalKey!

1 个答案:

答案 0 :(得分:0)

StreamFactory = new StreamFactory().withDefaultZkHost(zookeeper) .withFunctionName("search", CloudSolrStream.class) .withFunctionName("select", SelectStream.class) .withFunctionName("merge", MergeStream.class) .withFunctionName("sort", SortStream.class) .withFunctionName("tuple", TupStream.class) .withFunctionName("rollup", RollupStream.class) .withFunctionName("hashJoin", HashJoinStream.class) .withFunctionName("count", CountMetric.class) .withFunctionName("facet", FacetStream.class) .withFunctionName("sum", SumMetric.class) .withFunctionName("unique", UniqueStream.class) .withFunctionName("significantTerms", SignificantTermsStream.class) .withFunctionName("stats", StatsStream.class) .withFunctionName("innerJoin", InnerJoinStream.class) .withFunctionName("issnMerge", IssnMergeStream.class) .withFunctionName("intersect", IntersectStream.class) .withFunctionName("boostByEra", BoostBooksByEraExpression.class) .withFunctionName("determineRRec", DetermineRepresentativeRecord.class) .withFunctionName("plist", ParallelListStream.class) .withFunctionName("let", LetStream.class); 是保留用于描述GraphQL查询输入的关键字。您的架构应如下所示:

input

在GraphQL模式中定义enum KeyPrefix { (your values) } type PrimaryKey { prefix: KeyPrefix! key: Int! } type Item { pk: PrimaryKey! data: String! name: String! } 时,您将希望使用Query,如下所示:

input

这将允许客户使用与input PrimaryKeyInput { prefix: KeyPrefix! key: Int! } type Query { getItemByPrimaryKey(input: PrimaryKeyInput!): Item } 相同的字段来请求Item