Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var debug = require('debug')('primus-graphql:fixtures:graphql-schema')
var GraphQL = require('graphql')
var Relay = require('graphql-relay')
var db = require('./mem-db.js') // In memory database
var GraphQLRelaySubscription = require('graphql-relay-subscription')
var UserChangesIterator = require('./user-changes-iterator')
require('../../src/shared/subscription-dispose.js')
var relaySubscription = GraphQLRelaySubscription.subscriptionWithClientId
var GraphQLInputObjectType = GraphQL.GraphQLInputObjectType
var GraphQLSchema = GraphQL.GraphQLSchema
var GraphQLString = GraphQL.GraphQLString
var GraphQLNonNull = GraphQL.GraphQLNonNull
var GraphQLObjectType = GraphQL.GraphQLObjectType
// GraphQL types
var UserType = new GraphQLObjectType({
name: 'User',
description: 'user',
fields: {
id: { type: GraphQLString },
name: { type: GraphQLString },
idAndName: {
type: GraphQLString,
resolve: function (user) {
return user.id + ':' + user.name
}
const nameToType = (typeName, field) => {
const hasResolve = !!field.resolve;
switch (typeName) {
case 'ID':
return _graphql.GraphQLID;
case 'String':
return _graphql.GraphQLString;
case 'Float':
return _graphql.GraphQLFloat;
case 'Boolean':
return _graphql.GraphQLBoolean;
case 'Buffer':
return _customType.GraphQLBuffer;
case 'Date':
return _customType.GraphQLDate;
case 'Mixed':
return {};
default:
if (hasResolve) return _graphql.GraphQLID; // other models, use ID as reference
return null; // Object attribute in mongoose model
}
};
const graphqlHTTP = require('express-graphql');
const express = require('express');
const cors = require('cors');
const { logger } = require('@storybook/node-logger');
// Import the data you created above
const data = require('./data.json');
// Define the User type with two string fields: `id` and `name`.
// The type of User is GraphQLObjectType, which has child fields
// with their own types (in this case, GraphQLString).
const userType = new graphql.GraphQLObjectType({
name: 'User',
fields: {
id: { type: graphql.GraphQLString },
name: { type: graphql.GraphQLString },
},
});
// Define the schema with one top-level field, `user`, that
// takes an `id` argument and returns the User with that ID.
// Note that the `query` is a GraphQLObjectType, just like User.
// The `user` field, however, is a userType, which we defined above.
const schema = new graphql.GraphQLSchema({
query: new graphql.GraphQLObjectType({
name: 'Query',
fields: {
user: {
type: userType,
// `args` describes the arguments that the `user` query accepts
args: {
id: { type: graphql.GraphQLString },
test('Requires path argument', () => {
expect.assertions(2);
expect(resDef.fields()._get.args.path.type).toBeInstanceOf(graphql.GraphQLNonNull);
expect(graphql.GraphQLNonNull).toHaveBeenCalledWith(graphql.GraphQLString);
});
const bus = new ServerBus(
mean.fqelement, mean.ws, {}, mean.comp, mean.locs);
//////////////////////////////////////////////////
const grafo = new Grafo(mean.db);
console.log("calling schema");
const schema = grafo
.add_mutation({
name: "sendEmail",
"type": graphql.GraphQLBoolean,
args: {
to: {"type": graphql.GraphQLString},
content: {"type": graphql.GraphQLString}
},
resolve: (_, {to, content}) => {
console.log("Send email to " + to);
console.log("content:" + content);
return true;
}
})
.schema();
Helpers.serve_schema(mean.ws, schema);
grafo.init().then(_ => mean.start());
resolve: (_, {author_id, target_id}) => {
const queryObj = {};
if (author_id) queryObj["author.atom_id"] = author_id;
if (target_id) queryObj["target.atom_id"] = target_id;
return mean.db.collection("comments")
.find(queryObj)
.toArray();
}
})
.add_mutation({
name: "newComment",
type: "Comment",
args: {
author_id: {type: new graphql.GraphQLNonNull(graphql.GraphQLString)},
target_id: {type: new graphql.GraphQLNonNull(graphql.GraphQLString)},
content: {type: graphql.GraphQLString}
},
resolve: (_, {author_id, target_id, content}) => {
const atom_id = uuid.v4();
const commentObj = {
atom_id: atom_id,
author: {atom_id: author_id},
target: {atom_id: target_id},
content: content
};
return Promise.all([
mean.db.collection("comments").insertOne(commentObj),
bus.create_atom("Comment", atom_id, commentObj)
])
.then(() => mean.db.collection("comments").findOne({atom_id: atom_id}));
}
})
'use strict';
const _ = require('lodash');
const graphql = require('graphql');
const swagger = require('./swagger');
const __allTypes = {};
const toGraphQLTypes = {
string: graphql.GraphQLString,
date: graphql.GraphQLString,
integer: graphql.GraphQLInt,
number: graphql.GraphQLInt,
boolean: graphql.GraphQLBoolean,
file: graphql.GraphQLString
};
function isObjectType(jsonSchema) {
return jsonSchema.properties || jsonSchema.type === 'object' || jsonSchema.type === "array" || jsonSchema.schema;
}
function getTypeNameFromRef(ref) {
const cutRef = ref.replace('#/definitions/', '');
return cutRef.replace(/\//, '_');
}
function getExistingType(ref, isInputType) {
'use strict';
const graphql = require('graphql');
const PaymentCardType = new graphql.GraphQLObjectType({
name: 'PaymentCard',
fields: {
merchant: { type: graphql.GraphQLString },
lastFour: { type: graphql.GraphQLString }
}
});
module.exports = PaymentCardType;
'use strict';
const _ = require('lodash');
const graphql = require('graphql');
const swagger = require('./swagger');
const __allTypes = {};
const toGraphQLTypes = {
string: graphql.GraphQLString,
date: graphql.GraphQLString,
integer: graphql.GraphQLInt,
number: graphql.GraphQLInt,
boolean: graphql.GraphQLBoolean,
file: graphql.GraphQLString
};
function isObjectType(jsonSchema) {
return jsonSchema.properties || jsonSchema.type === 'object' || jsonSchema.type === "array" || jsonSchema.schema;
}
function getTypeNameFromRef(ref) {
const cutRef = ref.replace('#/definitions/', '');
return cutRef.replace(/\//, '_');
}
const GraphQLNonNull = require('graphql').GraphQLNonNull;
const GraphQLString = require('graphql').GraphQLString;
const bookType = require('../typeDefs/typeDef');
const BookModel = require('../../models/Book');
exports.addBook = {
type: bookType.bookType,
args: {
name: {
type: new GraphQLNonNull(GraphQLString),
},
author: {
type: new GraphQLNonNull(GraphQLString),
}
},
resolve: async (root, args) => {
const uModel = new BookModel(args);
const newBook = await uModel.save();