How to use the graphql.GraphQLString function in graphql

To help you get started, we’ve selected a few graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tjmehta / primus-graphql / test-browser / fixtures / graphql-schema.js View on Github external
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
      }
github wwayne / mooseql / lib / schema / buildArgs.js View on Github external
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
  }
};
github storybookjs / storybook / examples / official-storybook / graphql-server / index.js View on Github external
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 },
github chasingmaxwell / graphql-leveler / __tests__ / lib.js View on Github external
test('Requires path argument', () => {
      expect.assertions(2);
      expect(resDef.fields()._get.args.path.type).toBeInstanceOf(graphql.GraphQLNonNull);
      expect(graphql.GraphQLNonNull).toHaveBeenCalledWith(graphql.GraphQLString);
    });
github spderosso / deja-vu / catalog / messaging / email / src / app.ts View on Github external
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());
github spderosso / deja-vu / catalog / messaging / comment / src / app.ts View on Github external
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}));
    }
  })
github allograph / allograph / swagger / type_map.js View on Github external
'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) {
github storj / service-storage-models / lib / graphql / types / payment-card.js View on Github external
'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;
github allograph / allograph / swagger / type_map.js View on Github external
'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(/\//, '_');
}
github Traversal-Labs / starfleet / src / resolvers / AddBook.js View on Github external
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();