From d1e230c6fd7f9c34925d270551bd07f13d0e04f5 Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Sun, 31 Jan 2016 19:18:18 -0600 Subject: [PATCH] get rid of unnecessary list types --- config/graphql/schema.graphql | 43 +--- config/graphql/schema.json | 355 +++------------------------------- lib/relay/components/App.js | 8 +- models/house.js | 10 +- models/user.js | 3 +- 5 files changed, 35 insertions(+), 384 deletions(-) diff --git a/config/graphql/schema.graphql b/config/graphql/schema.graphql index 5dce13a..836384a 100644 --- a/config/graphql/schema.graphql +++ b/config/graphql/schema.graphql @@ -1,47 +1,20 @@ type House implements Node { id: ID! name: String! - power_data(after: String, first: Int, before: String, last: Int): PowerDatumConnection - habitants(after: String, first: Int, before: String, last: Int): UserConnection -} - -type HouseConnection { - pageInfo: PageInfo! - edges: [HouseEdge] -} - -type HouseEdge { - node: House - cursor: String! + power_data(after: String, first: Int, before: String, last: Int): [PowerDatum] + habitants(after: String, first: Int, before: String, last: Int): [User] } interface Node { id: ID! } -type PageInfo { - hasNextPage: Boolean! - hasPreviousPage: Boolean! - startCursor: String - endCursor: String -} - type PowerDatum implements Node { id: ID! power: Float time: Int } -type PowerDatumConnection { - pageInfo: PageInfo! - edges: [PowerDatumEdge] -} - -type PowerDatumEdge { - node: PowerDatum - cursor: String! -} - type Query { node(id: ID!): Node viewer: User @@ -50,15 +23,5 @@ type Query { type User implements Node { id: ID! username: String! - house: HouseConnection -} - -type UserConnection { - pageInfo: PageInfo! - edges: [UserEdge] -} - -type UserEdge { - node: User - cursor: String! + house: House } diff --git a/config/graphql/schema.json b/config/graphql/schema.json index ee80b96..f219e5c 100644 --- a/config/graphql/schema.json +++ b/config/graphql/schema.json @@ -193,9 +193,13 @@ } ], "type": { - "kind": "OBJECT", - "name": "PowerDatumConnection", - "ofType": null + "kind": "LIST", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "PowerDatum", + "ofType": null + } }, "isDeprecated": false, "deprecationReason": null @@ -246,9 +250,13 @@ } ], "type": { - "kind": "OBJECT", - "name": "UserConnection", - "ofType": null + "kind": "LIST", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "User", + "ofType": null + } }, "isDeprecated": false, "deprecationReason": null @@ -285,165 +293,6 @@ "enumValues": null, "possibleTypes": null }, - { - "kind": "OBJECT", - "name": "PowerDatumConnection", - "description": "A connection to a list of items.", - "fields": [ - { - "name": "pageInfo", - "description": "Information to aid in pagination.", - "args": [], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "PageInfo", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "edges", - "description": "Information to aid in pagination.", - "args": [], - "type": { - "kind": "LIST", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "PowerDatumEdge", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [], - "enumValues": null, - "possibleTypes": null - }, - { - "kind": "OBJECT", - "name": "PageInfo", - "description": "Information about pagination in a connection.", - "fields": [ - { - "name": "hasNextPage", - "description": "When paginating forwards, are there more items?", - "args": [], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Boolean", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "hasPreviousPage", - "description": "When paginating backwards, are there more items?", - "args": [], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Boolean", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "startCursor", - "description": "When paginating backwards, the cursor to continue.", - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "endCursor", - "description": "When paginating forwards, the cursor to continue.", - "args": [], - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [], - "enumValues": null, - "possibleTypes": null - }, - { - "kind": "SCALAR", - "name": "Boolean", - "description": "The `Boolean` scalar type represents `true` or `false`.", - "fields": null, - "inputFields": null, - "interfaces": null, - "enumValues": null, - "possibleTypes": null - }, - { - "kind": "OBJECT", - "name": "PowerDatumEdge", - "description": "An edge in a connection.", - "fields": [ - { - "name": "node", - "description": "The item at the end of the edge", - "args": [], - "type": { - "kind": "OBJECT", - "name": "PowerDatum", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "cursor", - "description": "A cursor for use in pagination", - "args": [], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [], - "enumValues": null, - "possibleTypes": null - }, { "kind": "OBJECT", "name": "PowerDatum", @@ -511,88 +360,6 @@ "enumValues": null, "possibleTypes": null }, - { - "kind": "OBJECT", - "name": "UserConnection", - "description": "A connection to a list of items.", - "fields": [ - { - "name": "pageInfo", - "description": "Information to aid in pagination.", - "args": [], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "PageInfo", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "edges", - "description": "Information to aid in pagination.", - "args": [], - "type": { - "kind": "LIST", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "UserEdge", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [], - "enumValues": null, - "possibleTypes": null - }, - { - "kind": "OBJECT", - "name": "UserEdge", - "description": "An edge in a connection.", - "fields": [ - { - "name": "node", - "description": "The item at the end of the edge", - "args": [], - "type": { - "kind": "OBJECT", - "name": "User", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "cursor", - "description": "A cursor for use in pagination", - "args": [], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [], - "enumValues": null, - "possibleTypes": null - }, { "kind": "OBJECT", "name": "User", @@ -636,7 +403,7 @@ "args": [], "type": { "kind": "OBJECT", - "name": "HouseConnection", + "name": "House", "ofType": null }, "isDeprecated": false, @@ -654,88 +421,6 @@ "enumValues": null, "possibleTypes": null }, - { - "kind": "OBJECT", - "name": "HouseConnection", - "description": "A connection to a list of items.", - "fields": [ - { - "name": "pageInfo", - "description": "Information to aid in pagination.", - "args": [], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "PageInfo", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "edges", - "description": "Information to aid in pagination.", - "args": [], - "type": { - "kind": "LIST", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "HouseEdge", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [], - "enumValues": null, - "possibleTypes": null - }, - { - "kind": "OBJECT", - "name": "HouseEdge", - "description": "An edge in a connection.", - "fields": [ - { - "name": "node", - "description": "The item at the end of the edge", - "args": [], - "type": { - "kind": "OBJECT", - "name": "House", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "cursor", - "description": "A cursor for use in pagination", - "args": [], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - } - ], - "inputFields": null, - "interfaces": [], - "enumValues": null, - "possibleTypes": null - }, { "kind": "OBJECT", "name": "__Schema", @@ -1077,6 +762,16 @@ ], "possibleTypes": null }, + { + "kind": "SCALAR", + "name": "Boolean", + "description": "The `Boolean` scalar type represents `true` or `false`.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, { "kind": "OBJECT", "name": "__Field", diff --git a/lib/relay/components/App.js b/lib/relay/components/App.js index 6548d40..7efe91c 100644 --- a/lib/relay/components/App.js +++ b/lib/relay/components/App.js @@ -4,7 +4,7 @@ import Relay from 'react-relay'; class App extends React.Component { render() { var viewer = this.props.viewer, - house = viewer.house.edges[0].node; + house = viewer.house; return (

Hi, {viewer.username}

@@ -20,11 +20,7 @@ export default Relay.createContainer(App, { fragment on User { username house { - edges { - node { - name - } - } + name } } `, diff --git a/models/house.js b/models/house.js index c291ec3..1ce5b5d 100644 --- a/models/house.js +++ b/models/house.js @@ -2,7 +2,8 @@ import { GraphQLNonNull, GraphQLObjectType, GraphQLInt, - GraphQLString + GraphQLString, + GraphQLList } from 'graphql'; import { @@ -49,16 +50,13 @@ var House = DB.sequelize.define(NAME, { name: NAME, description: 'A house', fields: () => { - var {connectionType: power_data_connection} = connectionDefinitions({name: DB.PowerDatum.name, nodeType: DB.PowerDatum.graphql_type}), - {connectionType: habitants_connection} = connectionDefinitions({name: DB.User.name, nodeType: DB.User.graphql_type}); - return { id: globalIdField(NAME), name: { type: new GraphQLNonNull(GraphQLString) }, power_data: { - type: power_data_connection, + type: new GraphQLList(DB.PowerDatum.graphql_type), description: "Returns house's power data.", args: connectionArgs, resolve: (house, args) => { @@ -66,7 +64,7 @@ var House = DB.sequelize.define(NAME, { } }, habitants: { - type: habitants_connection, + type: new GraphQLList(DB.User.graphql_type), description: "Returns list of house's habitants.", args: connectionArgs, resolve: (house, args) => { diff --git a/models/user.js b/models/user.js index b758ec3..5cd92ca 100644 --- a/models/user.js +++ b/models/user.js @@ -49,14 +49,13 @@ var User = DB.sequelize.define(NAME, { name: NAME, description: 'A house', fields: () => { - var {connectionType: house_connection} = connectionDefinitions({name: DB.House.name, nodeType: DB.House.graphql_type}); return { id: globalIdField(NAME), username: { type: new GraphQLNonNull(GraphQLString) }, house: { - type: house_connection, + type: DB.House.graphql_type, description: "Returns user's house.", resolve: (user, args) => { return user.getHouse();