首页 > 解决方案 > nested object in graphcool

问题描述

I have a model like this:

  type User @model {
    id: ID! @isUnique
  }

Now I want to add a nested object:

type User @model {
   id: ID! @isUnique
   position: {
      lat: Int
      lng: Int 
    }
}

but I get a error from Graphcool,

{", expected IgnoredNoComment, ImplementsInterfaces or Directives (line 4, column 11):
 type User @model {
      ^ 

Why? can't I pass a nested object? In this way I can update the mutation simply passing the object with lat and lng. What is wrong with this?

标签: graphqlreact-apollographcool

解决方案


对于嵌套结构,您需要为类型变量定义一个,如下所示

type User @model {
   id: ID! @isUnique
   position: Position
}
type Position {
  lat: Int
  lng: Int 
}

推荐阅读