Narcissistic, Perfectly Modest

    @currentdesk/prismatize
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.17-dev.45 • Public • Published

    Prismatize

    A node library that converts your database into a GraphQL API like Prisma.

    CLI Usage

    npx @currentdesk/prismatize expand ./input.graphql [./output.graphql]

    Import Examples

    MongoDb with Resolver Mapping

    import {
      expandSchema,
      mapResolvers,
    } from '@currentdesk/prismatize'
     
    // Using `graphql-import-loader`
    import types from './schema/index.graphql'
     
    const typeDefs = expandSchema(types, 'mongo')
    const resolvers = mapResolvers(typeDefs, {
      type: 'mongo',
      uri: '', // database connection uri
      database: '', // database name
    })

    Serverless Lambda with GraphQL-Yoga and MongoDb Resolver Mapping

    import {
      APIGatewayEvent,
      Callback,
      Context,
      Handler
    } from 'aws-lambda'
    import { GraphQLServerLambda } from 'graphql-yoga'
     
    import {
      expandSchema,
      mapResolvers,
    } from '@currentdesk/prismatize'
     
    // Using `graphql-import-loader`
    import types from './schema/index.graphql'
     
    const typeDefs = expandSchema(types, 'mongo')
    const resolvers = mapResolvers(typeDefs, {
      type: 'mongo',
      uri: '', // database connection uri
      database: '', // database name
    })
     
    const yogaLambda = new GraphQLServerLambda({
      typeDefs,
      resolvers,
    })
     
    export const graphql: Handler = (event: APIGatewayEvent, context: Context, callback: Callback) => {
      // allows function to re-use mongo connection for other events processed by this instance
      // https://www.mongodb.com/blog/post/optimizing-aws-lambda-performance-with-mongodb-atlas-and-nodejs
      context.callbackWaitsForEmptyEventLoop = false
     
      return yogaLambda.graphqlHandler(event, context, callback)
    }
     
    export const playground: Handler = (event: APIGatewayEvent, context: Context, callback: Callback) => {
      return yogaLambda.playgroundHandler(event, context, callback)
    }

    Keywords

    none

    Install

    npm i @currentdesk/prismatize

    DownloadsWeekly Downloads

    2

    Version

    0.1.17-dev.45

    License

    MIT

    Unpacked Size

    47.3 kB

    Total Files

    60

    Last publish

    Collaborators

    • patrick_reames
    • skywap
    • tjpeden
    • treydan