create valid relay schema.json
This commit is contained in:
20
config/graphql/node.js
Normal file
20
config/graphql/node.js
Normal 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};
|
||||
64
config/graphql/schema.graphql
Normal file
64
config/graphql/schema.graphql
Normal 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
27
config/graphql/schema.js
Normal 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
1522
config/graphql/schema.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user