From cb9c26cf456f16e3e9db2969aab3ccd828fe9208 Mon Sep 17 00:00:00 2001 From: Anthony Lee Date: Fri, 3 Nov 2017 11:39:57 -0500 Subject: [PATCH] Add list of users under company and fix circular reference --- graphql/schema/schema.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/graphql/schema/schema.js b/graphql/schema/schema.js index 62b80e9..acc1c98 100644 --- a/graphql/schema/schema.js +++ b/graphql/schema/schema.js @@ -5,16 +5,24 @@ const { GraphQLObjectType, GraphQLString, GraphQLInt, - GraphQLSchema + GraphQLSchema, + GraphQLList } = graphql; const CompanyType = new GraphQLObjectType({ name: 'Company', - fields: { + fields: () => ({ id: { type: GraphQLString }, name: { type: GraphQLString }, - description: { type: GraphQLString } - } + description: { type: GraphQLString }, + users: { + type: new GraphQLList(UserType), + resolve(parentValue, args) { + return axios.get(`http://localhost:3000/companies/${parentValue.id}/users`) + .then(resp => resp.data); + } + } + }) }); const UserType = new GraphQLObjectType({