Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function getNodeDefinitions(apiUrl, dbAlias) {
const db = consumer(apiUrl, dbAlias);
return nodeDefinitions(
(globalId) => {
const { type, id } = fromGlobalId(globalId);
return db.getEntity(id)
.then(entity => {
console.log(`type "${type}" entity:`, entity);
return entity;
});
},
(object) => {
console.log('get GraphQL type of object:', object);
// const registeredType = getRegisteredTypeForValueType(object.__type);
// FIXME: Return object type from node interface...
return null;
}
const init = () => {
// ==============================================
// Node interface
// ==============================================
mainStory.debug('gql', 'Creating interfaces...');
const { nodeInterface, nodeField } = nodeDefinitions(
getNodeFromGlobalId,
getNodeType(gqlTypes)
);
gqlInterfaces.Node = nodeInterface;
const nodeRootField = nodeField;
mainStory.debug('gql', 'Creating types...');
let configBaseField;
let keysBaseField;
// ==============================================
// Viewer
// ==============================================
gqlTypes.Viewer = new GraphQLObjectType({
name: 'Viewer',
interfaces: [gqlInterfaces.Node],
// @flow
import { nodeDefinitions } from "graphql-relay"
module.exports = nodeDefinitions(globalId => null)
// This module exports a GraphQL Schema, which is a declaration of all the
// types, queries and mutations we'll use in our system.
// Relay adds some specific types that it needs to function, including Node, Edge, Connection
// Firstly we need to create the Node interface in our system. This has nothing
// to do with Node.js! In Relay, Node refers to an entity – that is, an object
// with an ID.
// To create this interface, we need to pass in a resolving function as the
// first arg to nodeDefinitions that can fetch an entity given a global Relay
// ID. The second arg can be used to resolve an entity into a GraphQL type –
// but it's actually optional, so we'll leave it out and use isTypeOf on the
// GraphQL types further below.
var nodeDefinitions = GraphQLRelay.nodeDefinitions(function(globalId) {
var idInfo = GraphQLRelay.fromGlobalId(globalId)
if (idInfo.type == 'Image') {
return getImage(idInfo.id)
}
return null
})
var imageType = new GraphQL.GraphQLObjectType({
name: 'Image',
description: 'An image entity',
isTypeOf: function(obj) { return obj instanceof Image },
// We use a closure here because we need to refer to widgetType from above
fields: function() {
return {
id: GraphQLRelay.globalIdField('Image'),
onInit() {
const nodeIface = GraphQLRelay.nodeDefinitions(globalId => {
const node = GraphQLRelay.fromGlobalId(globalId);
return nodes[node.type](node.id);
}).nodeInterface;
this.registerInterface(nodeIface);
},
export default (context: SGContext): InterfaceContext => {
const interfaces: { [string]: GraphQLInterfaceType } = {
Node: nodeDefinitions((globalId) => {
const { type, id } = fromGlobalId(globalId)
console.log('Warning-------------------- node id Fetcher not implement' + type + ' ' + id)
}, (obj) => {
const type = obj._fieldType
const fieldType = context.fieldType(type)
if (fieldType) {
return (fieldType.outputType: any)
}
throw new Error(`Type ${type} not exist.`)
}).nodeInterface
}
return {
interface: (str) => {
return interfaces[str]
},
registerInterface: (name, gInterface) => {
return resolver(null, null, context);
}
return null;
};
const typeResolver = obj => {
const typeName = obj[RELAY_TYPE_PROMOTER_FIELD];
return graphRegistry.types[typeName]
? graphRegistry.types[typeName].type
: null;
};
return {
...nodeDefinitions(idFetcher, typeResolver),
idFetcher,
};
};
if (_.isNull(obj)) return null;
obj._dataType = type;
return obj;
}
function resolveType(obj) {
if (_.isNull(obj)) return null;
const { type } = resolvers[obj._dataType];
return type;
}
const {
nodeInterface,
nodeField,
} = relayNodeDefinitions(resolveObj, resolveType);
return {
registerType,
nodeInterface,
nodeField,
};
}
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE
*
* @flow
*/
import { fromGlobalId, nodeDefinitions } from "graphql-relay";
import Parse from "parse/node";
import typeRegistry from "./typeRegistry";
module.exports = nodeDefinitions(
globalId => {
const { type, id } = fromGlobalId(globalId);
return new Parse.Query(type).get(id);
},
obj => typeRegistry.lookup(obj.className)
);