create valid relay schema.json

This commit is contained in:
Eric Hulburd
2016-01-31 17:18:27 -06:00
parent 2c42090cd9
commit c0efde030d
20 changed files with 90004 additions and 266 deletions

View File

@@ -24,10 +24,10 @@ class Database {
// add associations
for (var model of Database.models){
model.associate();
model.set();
}
return sequelize.sync({force: true});
return sequelize.sync();
}
}
Database.sequelize = sequelize;

20
config/graphql/node.js Normal file
View File

@@ -0,0 +1,20 @@
import {
fromGlobalId,
nodeDefinitions,
} from 'graphql-relay';
var {nodeInterface, nodeField} = nodeDefinitions(
(globalId) => {
var {type, id} = fromGlobalId(globalId);
return null;
},
(obj) => {
if (obj instanceof Array) {
return Array;
} else {
return null;
}
}
);
export {nodeInterface, nodeField};

View File

@@ -0,0 +1,64 @@
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!
}
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
}
type User implements Node {
id: ID!
username: String!
house(after: String, first: Int, before: String, last: Int): HouseConnection
}
type UserConnection {
pageInfo: PageInfo!
edges: [UserEdge]
}
type UserEdge {
node: User
cursor: String!
}

27
config/graphql/schema.js Normal file
View File

@@ -0,0 +1,27 @@
import {
GraphQLObjectType,
GraphQLSchema
} from 'graphql';
import {nodeField} from './node';
import DB from './../database';
export default function(){
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField,
viewer: {
type: DB.User.graphql_type,
resolve: (_, args) => {
return DB.User.findOne({where: {username: args.username}});
}
},
}),
});
return new GraphQLSchema({
query: queryType
});
}

1522
config/graphql/schema.json Normal file

File diff suppressed because it is too large Load Diff