Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

graphql-anywhere promises test

node v6.17.1
version: 0.0.0
endpointsharetweet
require('graphql'); var { default: graphql } = require('graphql-anywhere'); var { default: gql } = require('graphql-tag'); var Promise = require('promise'); var _ = require('lodash'); function objectToPromise(object) { var keys = _.keys(object); var array = _.map(keys, (key) => { return object[key]; }); return Promise.all(array).then((values) => { return _.reduce(values, (object, value, k) => { object[keys[k]] = value; return object; }, Object.create(null)); }); }; function objectMapper(object, root) { return objectToPromise(object); }; var counter = 0; function resolver(name, root, args, context, info) { return new Promise((resolve) => { setTimeout(() => { Promise.resolve(root).then((value) => { if (name == 'getObject') { return resolve({}); } else if (name == 'getArray') { return resolve([{ getString: 'abc' }]); } else if (name == 'getString') { return resolve('something'); } }); }, 10); }); }; function execute(query, variables, context) { return graphql( resolver, query, null, context, variables, { resultMapper: objectMapper, } ); }; await execute(gql`{ getObject { getArray { getString } } }`).then()
Loading…

no comments

    sign in to comment