0.0.3 • Published 1 year ago

solid-start-create-api-graphql-handler v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

solid-start-create-api-graphql-handler

Description

solid-start-create-api-graphql-handler is a small utility function that allows to run a GraphQL server in a solid-start API route. This aims to fill this gap from the official solid-start documentation, which at the time of writing this package, there isn't any other solution out there.

Installation

npm install solid-start-create-api-graphql-handler
# pnpm i solid-start-create-api-graphql-handler
# yarn add solid-start-create-api-graphql-handler

Usage

import {createApiGraphQLHandler} from 'solid-start-create-api-graphql-handler'
import type {Handler} from 'solid-start-create-api-graphql-handler'

// Implement GraphQL schema
const typeDefs = gql``
// Implement GraphQL resolvers
const resolvers = {}

const server = new ApolloServer({ typeDefs, resolvers })
await server.start()

type Data = Record<string, unknown>

const handler: Handler<Data> = (res) => {
    if(res.success === false){
        const {errors} = res
        // process error response from the server
    }
    const {data} = res
    // process response from the server
}

export const POST = createApiGraphQLHandler({
    server,
    handler
})
0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago