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

@@ -1,33 +0,0 @@
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// Model types
class User extends Object {}
class Widget extends Object {}
// Mock data
var viewer = new User();
viewer.id = '1';
viewer.name = 'Anonymous';
var widgets = ['What\'s-it', 'Who\'s-it', 'How\'s-it'].map((name, i) => {
var widget = new Widget();
widget.name = name;
widget.id = `${i}`;
return widget;
});
module.exports = {
// Export methods that your schema can use to interact with your database
getUser: (id) => id === viewer.id ? viewer : null,
getViewer: () => viewer,
getWidget: (id) => widgets.find(w => w.id === id),
getWidgets: () => widgets,
User,
Widget,
};

89283
data/power_data.csv Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,143 +0,0 @@
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import {
GraphQLBoolean,
GraphQLFloat,
GraphQLID,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
} from 'graphql';
import {
connectionArgs,
connectionDefinitions,
connectionFromArray,
fromGlobalId,
globalIdField,
mutationWithClientMutationId,
nodeDefinitions,
} from 'graphql-relay';
import {
// Import methods that your schema can use to interact with your database
User,
Widget,
getUser,
getViewer,
getWidget,
getWidgets,
} from './database';
/**
* We get the node interface and field from the Relay library.
*
* The first method defines the way we resolve an ID to its object.
* The second defines the way we resolve an object to its GraphQL type.
*/
var {nodeInterface, nodeField} = nodeDefinitions(
(globalId) => {
var {type, id} = fromGlobalId(globalId);
if (type === 'User') {
return getUser(id);
} else if (type === 'Widget') {
return getWidget(id);
} else {
return null;
}
},
(obj) => {
if (obj instanceof User) {
return userType;
} else if (obj instanceof Widget) {
return widgetType;
} else {
return null;
}
}
);
/**
* Define your own types here
*/
var userType = new GraphQLObjectType({
name: 'User',
description: 'A person who uses our app',
fields: () => ({
id: globalIdField('User'),
widgets: {
type: widgetConnection,
description: 'A person\'s collection of widgets',
args: connectionArgs,
resolve: (_, args) => connectionFromArray(getWidgets(), args),
},
}),
interfaces: [nodeInterface],
});
var widgetType = new GraphQLObjectType({
name: 'Widget',
description: 'A shiny widget',
fields: () => ({
id: globalIdField('Widget'),
name: {
type: GraphQLString,
description: 'The name of the widget',
},
}),
interfaces: [nodeInterface],
});
/**
* Define your own connection types here
*/
var {connectionType: widgetConnection} =
connectionDefinitions({name: 'Widget', nodeType: widgetType});
/**
* This is the type that will be the root of our query,
* and the entry point into our schema.
*/
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField,
// Add your own root fields here
viewer: {
type: userType,
resolve: () => getViewer(),
},
}),
});
/**
* This is the type that will be the root of our mutations,
* and the entry point into performing writes in our schema.
*/
var mutationType = new GraphQLObjectType({
name: 'Mutation',
fields: () => ({
// Add your own mutations here
})
});
/**
* Finally, we construct our schema (whose starting query type is the query
* type we defined above) and export it.
*/
export var Schema = new GraphQLSchema({
query: queryType,
// Uncomment the following after adding some mutation fields:
// mutation: mutationType
});

File diff suppressed because it is too large Load Diff

5
data/users.csv Normal file
View File

@@ -0,0 +1,5 @@
tom,1
fred,1
bethany,2
sally,3
saray,2
1 tom 1
2 fred 1
3 bethany 2
4 sally 3
5 saray 2