-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8610794
Showing
21 changed files
with
4,314 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"passPerPreset": true, | ||
"presets": [ | ||
{ | ||
"plugins": [ | ||
"./build/babelRelayPlugin" | ||
] | ||
}, | ||
"react", | ||
"es2015", | ||
"stage-0" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"env": { | ||
"browser": true, | ||
"amd": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"rules": { | ||
"comma-dangle": 1, | ||
"quotes": [ 1, "single" ], | ||
"no-undef": 1, | ||
"global-strict": 0, | ||
"no-extra-semi": 1, | ||
"no-underscore-dangle": 0, | ||
"no-console": 0, | ||
"no-unused-vars": 1, | ||
"no-trailing-spaces": [1, { "skipBlankLines": true }], | ||
"no-unreachable": 1, | ||
"no-alert": 0, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
node_modules | ||
npm-debug.log | ||
data/schema.graphql | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
BSD License | ||
|
||
For Relay Starter Kit software | ||
|
||
Copyright (c) 2013-2015, Facebook, Inc. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name Facebook nor the names of its contributors may be used to | ||
endorse or promote products derived from this software without specific | ||
prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Additional Grant of Patent Rights Version 2 | ||
|
||
"Software" means the Relay Starter Kit software distributed by Facebook, Inc. | ||
|
||
Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software | ||
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable | ||
(subject to the termination provision below) license under any Necessary | ||
Claims, to make, have made, use, sell, offer to sell, import, and otherwise | ||
transfer the Software. For avoidance of doubt, no license is granted under | ||
Facebook's rights in any patent claims that are infringed by (i) modifications | ||
to the Software made by you or any third party or (ii) the Software in | ||
combination with any software or other technology. | ||
|
||
The license granted hereunder will terminate, automatically and without notice, | ||
if you (or any of your subsidiaries, corporate affiliates or agents) initiate | ||
directly or indirectly, or take a direct financial interest in, any Patent | ||
Assertion: (i) against Facebook or any of its subsidiaries or corporate | ||
affiliates, (ii) against any party if such Patent Assertion arises in whole or | ||
in part from any software, technology, product or service of Facebook or any of | ||
its subsidiaries or corporate affiliates, or (iii) against any party relating | ||
to the Software. Notwithstanding the foregoing, if Facebook or any of its | ||
subsidiaries or corporate affiliates files a lawsuit alleging patent | ||
infringement against you in the first instance, and you respond by filing a | ||
patent infringement counterclaim in that lawsuit against that party that is | ||
unrelated to the Software, the license granted hereunder will not terminate | ||
under section (i) of this paragraph due to such counterclaim. | ||
|
||
A "Necessary Claim" is a claim of a patent owned by Facebook that is | ||
necessarily infringed by the Software standing alone. | ||
|
||
A "Patent Assertion" is any lawsuit or other action alleging direct, indirect, | ||
or contributory infringement or inducement to infringe any patent, including a | ||
cross-claim or counterclaim. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Relay Starter Kit | ||
|
||
This kit includes an app server, a GraphQL server, and a transpiler that you can use to get started building an app with Relay. For a walkthrough, see the [Relay tutorial](https://facebook.github.io/relay/docs/tutorial.html). | ||
|
||
## Installation | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
## Running | ||
|
||
Start a local server: | ||
|
||
``` | ||
npm start | ||
``` | ||
|
||
## Developing | ||
|
||
Any changes you make to files in the `js/` directory will cause the server to | ||
automatically rebuild the app and refresh your browser. | ||
|
||
If at any time you make changes to `data/schema.js`, stop the server, | ||
regenerate `data/schema.json`, and restart the server: | ||
|
||
``` | ||
npm run update-schema | ||
npm start | ||
``` | ||
|
||
## License | ||
|
||
Relay Starter Kit is [BSD licensed](./LICENSE). We also provide an additional [patent grant](./PATENTS). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var getbabelRelayPlugin = require('babel-relay-plugin'); | ||
var schema = require('../data/schema.json'); | ||
|
||
module.exports = getbabelRelayPlugin(schema.data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* 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 {} | ||
class Widget {} | ||
|
||
// 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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
'use strict'; | ||
|
||
import merge from 'merge'; | ||
import { | ||
GraphQLBoolean, | ||
//GraphQLFloat, | ||
//GraphQLID, | ||
GraphQLInt, | ||
GraphQLList, | ||
//GraphQLNonNull, | ||
GraphQLObjectType, | ||
GraphQLSchema, | ||
GraphQLString, | ||
GraphQLUnionType | ||
} from 'graphql'; | ||
|
||
|
||
|
||
import session from './opcua'; | ||
|
||
|
||
|
||
|
||
|
||
// http://node-opcua.github.io/api_doc/classes/QualifiedName.html | ||
const QualifiedNameType = new GraphQLObjectType({ | ||
name: 'QualifiedName', | ||
fields: { | ||
namespaceIndex: { type: GraphQLInt }, | ||
name: { type: GraphQLString } | ||
} | ||
}); | ||
|
||
// http://node-opcua.github.io/api_doc/classes/QualifiedName.html | ||
const LocalizedTextType = new GraphQLObjectType({ | ||
name: 'LocalizedText', | ||
fields: { | ||
text: { type: GraphQLString }, | ||
locale: { type: GraphQLString } // says localId?? | ||
} | ||
}); | ||
|
||
|
||
|
||
const BooleanValueType = new GraphQLObjectType({ | ||
name: 'BooleanValue', | ||
fields: { | ||
value: { type: GraphQLBoolean }, | ||
dataType: { type: GraphQLString }, | ||
arrayType: { type: GraphQLString }, | ||
dimensions: { type: GraphQLInt }, | ||
expired: { type: GraphQLBoolean } | ||
} | ||
}); | ||
|
||
const BooleanArrayValueType = new GraphQLObjectType({ | ||
name: 'BooleanArrayValue', | ||
fields: { | ||
value: { type: new GraphQLList(GraphQLBoolean)}, | ||
dataType: { type: GraphQLString }, | ||
arrayType: { type: GraphQLString }, | ||
dimensions: { type: GraphQLInt }, | ||
expired: { type: GraphQLBoolean } | ||
} | ||
}); | ||
|
||
|
||
|
||
const ValueType = new GraphQLUnionType({ | ||
name: 'Value', | ||
types: [BooleanValueType, BooleanArrayValueType], | ||
resolveType(value){ | ||
if (value.arrayType === 1) { | ||
console.log('it was bool array!', value.arrayType); | ||
return BooleanArrayValueType; | ||
} | ||
else { | ||
console.log('it was bool!'); | ||
return BooleanValueType; | ||
} | ||
} | ||
}); | ||
|
||
const StatusCodeType = new GraphQLObjectType({ | ||
name: 'StatusCode', | ||
fields: { | ||
value: { type: GraphQLInt }, | ||
description: { type: GraphQLString }, | ||
name: { type: GraphQLString } | ||
} | ||
}); | ||
|
||
|
||
|
||
|
||
// http://node-opcua.github.io/api_doc/classes/DataValue.html | ||
const DataValueType = new GraphQLObjectType({ | ||
name: 'DataValueType', | ||
fields: { | ||
serverPicoseconds: { type: GraphQLInt }, | ||
serverTimestamp: { type: GraphQLString }, //needs type | ||
sourcePicoseconds: { type: GraphQLInt }, | ||
sourceTimestamp: { type: GraphQLString }, //needs type | ||
value: { type: ValueType }, //needs type | ||
stringValue: { type: GraphQLString }, | ||
statusCode: { type: StatusCodeType } //needs type | ||
} | ||
}); | ||
|
||
|
||
|
||
|
||
|
||
// http://node-opcua.github.io/api_doc/classes/ReferenceDescription.html | ||
const ReferenceDescriptionType = new GraphQLObjectType({ | ||
name: 'ReferenceDescription', | ||
fields: ()=>({ | ||
browseName: {type: QualifiedNameType}, | ||
displayName: {type: LocalizedTextType}, | ||
isForward: {type: GraphQLBoolean}, | ||
nodeClass: { type: GraphQLString }, | ||
nodeId: { type: GraphQLString }, //?? | ||
referenceTypeId: { type: GraphQLString }, | ||
typeDefinition: { type: GraphQLString }, //?? | ||
value: { | ||
type: DataValueType, | ||
resolve: (reference) =>new Promise(function(resolve, reject){ | ||
session().readVariableValue(reference.nodeId, function(err, dataValue) { | ||
if (!err) { | ||
console.log(JSON.stringify(dataValue)); | ||
resolve(merge(true, dataValue, {stringValue: JSON.stringify(dataValue.value ? dataValue.value.value : null)})); | ||
} | ||
else { | ||
reject(err); | ||
} | ||
}); | ||
|
||
}) | ||
}, | ||
references: { | ||
type: new GraphQLList(ReferenceDescriptionType), | ||
resolve: (reference) => { | ||
return new Promise(function(resolve, reject){ | ||
session().browse(reference.nodeId, function(err, browseResult){ | ||
if(!err) { | ||
resolve(browseResult[0].references); | ||
} | ||
else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
const BrowseTargetType = new GraphQLObjectType({ | ||
name: 'BrowseTarget', | ||
fields: ()=>({ | ||
nodeId: { type: GraphQLString }, //?? | ||
references: {type: new GraphQLList(ReferenceDescriptionType)} | ||
}) | ||
}); | ||
|
||
|
||
// Define our schema, with one top level field, named `user`, that | ||
// takes an `id` argument and returns the User with that ID. | ||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: 'Query', | ||
fields: { | ||
user: { | ||
type: BrowseTargetType, | ||
args: { | ||
nodeId: { type: GraphQLString }, | ||
}, | ||
resolve: function (_, args) { | ||
return new Promise(function(resolve, reject){ | ||
session().browse(args.nodeId, function(err, browseResult){ | ||
if(!err) { | ||
console.log(JSON.stringify(browseResult, null, '\t')); | ||
resolve({ | ||
nodeId: args.nodeId, | ||
references: browseResult[0].references | ||
}); | ||
} | ||
else { | ||
reject(err); | ||
} | ||
}); | ||
|
||
}); | ||
} | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
export {schema as default}; | ||
|
||
|
Oops, something went wrong.