Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relay compatibility #27

Merged
merged 1 commit into from
Oct 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

104 changes: 6 additions & 98 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "airbnb/base",
"ecmaFeatures": {
"blockBindings": true,
"forOf": true,
Expand All @@ -17,102 +18,9 @@
},
"parser": "babel-eslint",
"rules": {
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": [2, "never"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"constructor-super": 2,
"curly": [2, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": [2, 2, { "indentSwitchCase": true }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-empty-label": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": 2,
"no-unreachable": 2,
"no-useless-call": 2,
"no-with": 2,
"one-var": [2, { "initialized": "never" }],
"operator-linebreak": [2, "after"],
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"space-after-keywords": [2, "always"],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, "always"],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [2, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
"yoda": [2, "never"]
"no-shadow": 0,
"no-param-reassign": 0,
"id-length": [2, {"exceptions": ["_", "i"]}],
"comma-dangle": [1, "never"]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
logs
*.log
lib
dist

# Runtime data
pids
Expand Down
4 changes: 4 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"preset": "airbnb",
"requireTrailingComma": false
}
25 changes: 0 additions & 25 deletions .jshintrc

This file was deleted.

73 changes: 39 additions & 34 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
import koa from 'koa';
import serve from 'koa-static';
import mongoose from 'mongoose';
import {getSchema, graphql} from '../src';
import graffiti from '@risingstack/graffiti';
import graffitiMongoose from '../src';

import User from './user';

var schema = getSchema([User]);
const port = process.env.PORT || 8080;

mongoose.connect('mongodb://localhost/graphql');
mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/graphql');

var query = `
query GetUser {
user(_id: "559645cd1a38532d14349246") {
...UserFragment
friends {
...UserFragment
}
User.remove();
const users = [];
for (let i = 0; i < 100; i++) {
const user = new User({
name: `User${i}`,
age: i,
createdAt: new Date() + i * 100,
friends: users.map((i) => i._id),
nums: [0, i],
bools: [true, false],
strings: ['foo', 'bar'],
removed: false,
body: {
eye: 'blue',
hair: 'yellow'
}
}

fragment UserFragment on User {
name
age
}
`;

// query = `{
// users(age: 19) {
// name
// age
// createdAt
// removed
// friends {
// name
// age
// }
// }
// }`;

graphql(schema, query)
.then((res) => console.log(JSON.stringify(res, false, 2)))
.catch((err) => console.error(err));
});
users.push(user);
user.save();
}

const app = koa();

// attach graffiti-mongoose middleware
app.use(graffiti.koa({
prefix: '/graphql',
adapter: graffitiMongoose,
models: [User]
}));

app.use(serve(__dirname + '/dist'));

app.listen(port);
console.log(`Started on http://localhost:${port}/`);
7 changes: 7 additions & 0 deletions example/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

rm -rf dist/ && mkdir -p dist/ &&
cp node_modules/graphiql/graphiql.css dist/graphiql.css &&
cp node_modules/graphiql/graphiql.min.js dist/graphiql.min.js &&
cp node_modules/react/dist/react.min.js dist/react.min.js &&
cat index.html > dist/index.html
92 changes: 92 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!--
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
-->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./graphiql.css" />
<script src="./react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/0.9.0/fetch.min.js"></script>
<script src="./graphiql.min.js"></script>
</head>
<body>
Loading...
<script>

/**
* This GraphiQL example illustrates how to use some of GraphiQL's props
* in order to enable reading and updating the URL parameters, making
* link sharing of queries a little bit easier.
*
* This is only one example of this kind of feature, GraphiQL exposes
* various React params to enable interesting integrations.
*/

// Parse the search string to get url parameters.
var search = window.location.search;
var parameters = {};
search.substr(1).split('&').forEach(function (entry) {
var eq = entry.indexOf('=');
if (eq >= 0) {
parameters[decodeURIComponent(entry.slice(0, eq))] =
decodeURIComponent(entry.slice(eq + 1));
}
});

// if variables was provided, try to format it.
if (parameters.variables) {
try {
parameters.variables =
JSON.stringify(JSON.parse(parameters.variables), null, 2);
} catch (e) {
// Do nothing, we want to display the invalid JSON as a string, rather
// than present an error.
}
}

// When the query and variables string is edited, update the URL bar so
// that it can be easily shared
function onEditQuery(newQuery) {
parameters.query = newQuery;
updateURL();
}

function onEditVariables(newVariables) {
parameters.variables = newVariables;
updateURL();
}

function updateURL() {
var newSearch = '?' + Object.keys(parameters).map(function (key) {
return encodeURIComponent(key) + '=' +
encodeURIComponent(parameters[key]);
}).join('&');
history.replaceState(null, null, newSearch);
}

// Defines a GraphQL fetcher using the fetch API.
function graphQLFetcher(graphQLParams) {
return fetch(window.location.origin + '/graphql?q=' + graphQLParams.query).then(function (response) {
return response.json()
});
}

// Render <GraphiQL /> into the body.
React.render(
React.createElement(GraphiQL, {
fetcher: graphQLFetcher,
query: parameters.query,
variables: parameters.variables,
onEditQuery: onEditQuery,
onEditVariables: onEditVariables
}),
document.body
);
</script>
</body>
</html>
19 changes: 16 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
{
"name": "graffiti-mongoose-example",
"version": "1.0.0",
"main": "index.js",
"description": "An example using graffiti-mongoose",
"scripts": {
"start": "node index.js"
"start": "node index.js",
"prestart": "npm run build",
"build": ". build.sh"
},
"dependencies": {
"@risingstack/graffiti": "^1.0.2",
"@risingstack/graffiti-mongoose": "../",
"babel-runtime": "^5.8.20",
"graphiql": "^0.3.1",
"koa": "^1.0.0",
"koa-static": "^1.4.9",
"react": "0.13.3"
},
"devDependencies": {
"babel": "^5.8.21"
}
}
Loading