ivansglazunov's notebooks

  • Deep create messaging package - /ivansglazunov/deep-create-messaging-package
    Last edited 2 years ago
    Copy and insert on 11 line path to your gql. (Recoment to use deep in cloud https://ivansglazunov.notion.site/Install-and-Using-8f213fbd532e4c869626b061b691ba2c in Gitpod developer cloud environment. Gql you can take from https://ivansglazunov.notion.site/GraphQL-12a676a2508541cf9a63cfeb564ffe7d).
  • Deep RunKit - /ivansglazunov/deep-runkit
    Last edited 3 years ago
    Prepare utilities... Require modules. Create http/https/ws/wss connection automatically. (Copy and insert on 11 line path to your gql.
  • GraphQL little something - /ivansglazunov/graphql-little-something
    Last edited 7 years ago
    var { graphql, GraphQLSchema: Schema, GraphQLObjectType: ObjectT, GraphQLString: StringT, GraphQLScalarType: ScalarT, } = require('graphql'); require('babel-runtime/core-js/object/values'); require('graphql-tools'); var { mergeTypes } = require('merge-graphql-schemas'); var Query = new ObjectT({ name: 'query', fields: () => ({ get: { type: StringT, resolve() { return 'sometihng getted'; }, }, scal: { type: new ScalarT({ name: 'scalarius', serialize: (value) => value, }), resolve() { return [{ a: 1, b: 2, }, { c: 3, }] }, } }), }); var schema = new Schema({ query: Query, }); graphql(schema, `{ get, scal }`).then((result) => { console.log(result); });
  • graphql-anywhere promises test - /ivansglazunov/graphql-anywhere-promises-test
    Last edited 7 years ago
    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()
  • ancient-storage - /ivansglazunov/abstract-storage
    Last edited 7 years ago
    require('graphql'); var { default: graphql } = require('graphql-anywhere'); var { default: gql } = require('graphql-tag'); var minimongo = require("minimongo"); var Promise = require('promise'); var _ = require('lodash'); var LocalDb = minimongo.MemoryDb; db = new LocalDb(); // Add a collection to the database db.addCollection("ancient"); function promiseMapper(object, root) { const keys = Object.keys(object); const valuesAndPromises = keys.map(name => object[name]); console.log([object, root]); return Promise.all(valuesAndPromises).then( values => values.reduce((resolvedObject, value, i) => { resolvedObject[keys[i]] = value; return resolvedObject; }, Object.create(null)), ); }; function generateMongoSelector(selector) { var newSelector = {}; for (var key in selector) { if (key == 'or') { } else if (key == 'and') { } } return newSelector; }; function resolver(name, root, args) { return new Promise((resolve, reject) => { if (name == 'insert') { db.ancient.upsert(args || {}, (doc) => { resolve({ id: `ancient/${doc._id}`, doc: doc, }); }); } else if (name == 'find') { db.ancient.find(generateMongoSelector(args)).fetch((docs, error) => { resolve({ count: docs.length, docs: docs.map((doc) => ({ id: doc._id, data: doc })), }); }); } else if (name == 'save') { if (!root.id) { resolve({ error: "not-founded", }); } else { resolve({ result: true, }); } } else if (name == 'docs') { root.then((root) => { console.warn(root[name]); resolve(root[name] || null); }); } else { root.then((root) => { resolve(root[name] || null); }); } }); }; function execute(query, variables, context) { return graphql(resolver, query, null, context, variables, { resultMapper: promiseMapper }); } exports.default = execute; db.ancient
  • GraphQL links - /ivansglazunov/graphql-links
    Last edited 7 years ago
    Dependencies
  • Example of recursion GraphQL query and schema - /ivansglazunov/example-of-recursion-graphql-query-and-schema
    Last edited 7 years ago
    var { graphql, GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLInterfaceType, buildSchema, } = require('graphql'); var hero = new GraphQLObjectType({ name: 'hero', fields: () => ({ name: { type: GraphQLString, }, hero: { type: hero, } }), }); var query = new GraphQLObjectType({ name: 'query', fields: { hero: { type: hero, }, }, }); var schema = new GraphQLSchema({ query: query, }); var resolvers = {}; resolvers.hero = { name: () => 'abc', }; resolvers.hero.hero = resolvers.hero; await graphql(schema, ` { hero { name hero { name hero { name hero { name } } } } } `, resolvers).then()
  • My First Playground - /ivansglazunov/my-first-playground
    Last edited 8 years ago
    var f = require("ancient-funicular"); console.log(f);