New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

battie

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

battie

A Batty tool for building GraphQL backends

latest
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

Battie

Battie is a batty microkernel tool for composing GraphQL APIs from a collection of Plugins.

You can think of it as a schema stitcher with some smarts.

const { App } = require('..')

// Core Plugin that defines a User type
const corePlugin = {
    typeDefs: `
        type Query { me: User }
        type User { id: ID! name: String! } 
    `,
    resolvers: {
        Query: {
            me(_, __, { app }) {
                app.emit('hello', 'world!') // app is an event emitter

                return { id: "user1", name: "Bob" }
            }
        }
    },
    setup(app) {
        // register a handler that can be used from any other plugin
        app.handler('log', (...args) => console.log("LOG:", ...args))
    }
}

// Extends the core to tracks emails for each user
const emailPlugin = {
    setup(app) {
        // register for event notifications from the app
        app.on('hello', (...args) => {
            console.log('EVENT:', ...args)
        })
    },
    typeDefs: `
        type User {
            emails : [Email]
        }
        type Email {
            subject: String
        }
    `,
    resolvers: {
        User: {
            async emails(user, _, { app }) {
                await app.handle('log', 'Requesting emails!')

                return [{
                    subject: "Test 1"
                }, {
                    subject: "Test 2"
                }]
            }
        }
    },
}

const app = new App([
    corePlugin,
    emailPlugin
])

const result = app.execute(`
    query {
        me {
            id
            name
            emails {
                subject
            }
        }
    }
`)

result.then(result => {
    console.log(JSON.stringify(result, null, 2))
})

FAQs

Package last updated on 14 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts