简体   繁体   中英

GraphQL: relationships in not normalizable

I am new to GraphQL not sure what I am doing wrong. Any help will be appreciated. I have included my GraphQL schema, data and query here. I am getting exception in query "Value to set in Organization.relationships in not normalizable: Value to set in Relationships.customers in not normalizable: should be an object or null or undefined".

My Schema:

type Query{
     searchForOrganization: [Organization!]!
}

type Data{
    id: ID
    type: String
}

type Group{
  data:[Data]
}

type User{
    data:[Data]
}

type Customer{
    data:[Data]
}

type Relationships{
    groups: Group
    users: User
    customers: Customer
}

type Attributes{
    name: String!
    description: String
    authenticationUrl: String
}

type Organization{
    id: ID!
    type: String!
    attributes: Attributes!
    relationships: Relationships!

}

Mock Data:

const mocks = {
    Query: () => ({
      searchForOrganization: () => [...new Array(9)],
    }),
    Organization: () => (
        {
            type: () => "organization",
            id: () =>"Test002",
            attributes: ()=>{
                return{
                authenticationUrl: "https://demo-hierarchies.test.intershop.com/INTERSHOP/rest/WFS/inSPIRED-inTRONICS_Business-Site/rest/",
                description: "Test Company",
                "name": "Test Company"
                };
            },
            relationships: () => {
                return{
                    customers: () => {
                        return{
                       data: [{type: "customer", id: "Test002_Root_customers"},
                                {type: "customer", id: "Test003_Root_customers"}
                            ]
                    };},
                    groups: () => {
                        return{
                        data: [{type: "group", id: "Test003_Root_groups"},
                            {type: "group", id: "Test002_Root_groups"}]
                        };},
                    users: () => {
                        return{
                        data: [{type: "user", id: "Test003_Root_users"},
                        {type: "user", id: "Test002_Root_users"}]
                        };}
                };
            }
          }
),
};

My Query:

query SearchForOrganization {
  searchForOrganization {
    id
    type
    attributes {
      name
      description
      authenticationUrl
    }
    relationships {
      groups {
        data {
          id
          type
        }
        
      }
      users {
        data {
          id
          type
        }
      }
      customers {
        data {
          id
          type
        }
      }
    }
  }
}

My Result:

{
  "errors": [
    {
      "message": "Value to set in Organization.relationships in not normalizable: Value to set in Relationships.customers in not normalizable: should be an object or null or undefined. Received () => {\r\n                        return{\r\n                       data: [{type: \"customer\", id: \"Test002_Root_customers\"},\r\n                                {type: \"customer\", id: \"Test003_Root_customers\"}\r\n                            ]\r\n                    };}",
      "locations": [
        {
          "line": 10,
          "column": 5
        }
      ],
      "path": [
        "searchForOrganization",
        0,
        "relationships"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Value to set in Organization.relationships in not normalizable: Value to set in Relationships.customers in not normalizable: should be an object or null or undefined. Received () => {\r",
            "                        return{\r",
            "                       data: [{type: \"customer\", id: \"Test002_Root_customers\"},\r",
            "                                {type: \"customer\", id: \"Test003_Root_customers\"}\r",
            "                            ]\r",
            "                    };}",

Change in schema solved the issue

type TypeAndID{
    id: ID
    type: String
}

type DataGroup{
  data:[TypeAndID]
}

type OrgRelationships{
    groups: DataGroup
    users: DataGroup
    customers: DataGroup
}

type Attributes{
    name: String!
    description: String
    authenticationUrl: String
}

type Organization{
    id: ID!
    type: String!
    attributes: Attributes!
    relationships: OrgRelationships!

}

type Data{
 data: [Organization!]!
}

type Query{
   
    getOrganizations: Data
   
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM