chore(graphql-server): setup
parent
3f6f302864
commit
094c2666d0
|
@ -0,0 +1,25 @@
|
||||||
|
name: ci-graphql-server
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'packages/graphql-server/**'
|
||||||
|
pull_request:
|
||||||
|
branches: ['*']
|
||||||
|
paths:
|
||||||
|
- 'packages/graphql-server/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ci:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ./packages/graphql-server
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 16.x
|
||||||
|
- run: yarn install --frozen-lockfile
|
||||||
|
- run: yarn build
|
||||||
|
- run: yarn test
|
|
@ -9,6 +9,7 @@
|
||||||
"build:hello": "yarn workspace @hono/hello build",
|
"build:hello": "yarn workspace @hono/hello build",
|
||||||
"build:zod-validator": "yarn workspace @hono/zod-validator build",
|
"build:zod-validator": "yarn workspace @hono/zod-validator build",
|
||||||
"build:qwik-city": "yarn workspace @hono/qwik-city build",
|
"build:qwik-city": "yarn workspace @hono/qwik-city build",
|
||||||
|
"build:graphql-server": "yarn workspace @hono/graphql-server build",
|
||||||
"build": "run-p build:*"
|
"build": "run-p build:*"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
const { defineConfig } = require('eslint-define-config')
|
|
||||||
|
|
||||||
module.exports = defineConfig({
|
|
||||||
root: true,
|
|
||||||
extends: [
|
|
||||||
'eslint:recommended',
|
|
||||||
'plugin:node/recommended',
|
|
||||||
'plugin:@typescript-eslint/recommended',
|
|
||||||
'prettier',
|
|
||||||
],
|
|
||||||
parser: '@typescript-eslint/parser',
|
|
||||||
parserOptions: {
|
|
||||||
sourceType: 'module',
|
|
||||||
ecmaVersion: 2021,
|
|
||||||
},
|
|
||||||
plugins: ['@typescript-eslint', 'import'],
|
|
||||||
globals: {
|
|
||||||
fetch: false,
|
|
||||||
Response: false,
|
|
||||||
Request: false,
|
|
||||||
addEventListener: false,
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
quotes: ['error', 'single'],
|
|
||||||
semi: ['error', 'never'],
|
|
||||||
'no-debugger': ['error'],
|
|
||||||
'no-empty': ['warn', { allowEmptyCatch: true }],
|
|
||||||
'no-process-exit': 'off',
|
|
||||||
'no-useless-escape': 'off',
|
|
||||||
'prefer-const': [
|
|
||||||
'warn',
|
|
||||||
{
|
|
||||||
destructuring: 'all',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'@typescript-eslint/ban-types': [
|
|
||||||
'error',
|
|
||||||
{
|
|
||||||
types: {
|
|
||||||
Function: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'sort-imports': 0,
|
|
||||||
'import/order': [2, { alphabetize: { order: 'asc' } }],
|
|
||||||
|
|
||||||
'node/no-missing-import': 'off',
|
|
||||||
'node/no-missing-require': 'off',
|
|
||||||
'node/no-deprecated-api': 'off',
|
|
||||||
'node/no-unpublished-import': 'off',
|
|
||||||
'node/no-unpublished-require': 'off',
|
|
||||||
'node/no-unsupported-features/es-syntax': 'off',
|
|
||||||
|
|
||||||
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
|
|
||||||
'@typescript-eslint/no-empty-interface': 'off',
|
|
||||||
'@typescript-eslint/no-inferrable-types': 'off',
|
|
||||||
'@typescript-eslint/no-var-requires': 'off',
|
|
||||||
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
|
|
||||||
},
|
|
||||||
})
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"printWidth": 100,
|
|
||||||
"trailingComma": "es5",
|
|
||||||
"tabWidth": 2,
|
|
||||||
"semi": false,
|
|
||||||
"singleQuote": true,
|
|
||||||
"jsxSingleQuote": true,
|
|
||||||
"endOfLine": "lf"
|
|
||||||
}
|
|
|
@ -1,11 +1,5 @@
|
||||||
# GraphQL Server Middleware
|
# GraphQL Server Middleware
|
||||||
|
|
||||||
## Information
|
|
||||||
|
|
||||||
GraphQL Server Middleware `@honojs/graphql-server` is renamed to `@hono/graphql-server`.
|
|
||||||
`@honojs/graphql-server` is not maintained, please use `@hono/graphql-server`.
|
|
||||||
Also, for Deno, you can use import with `npm:` prefix like `npm:@hono/graphql-server`.
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
This middleware depends on [GraphQL.js](https://www.npmjs.com/package/graphql).
|
This middleware depends on [GraphQL.js](https://www.npmjs.com/package/graphql).
|
||||||
|
@ -53,3 +47,7 @@ app.use(
|
||||||
|
|
||||||
app.fire()
|
app.fire()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
Minghe Huang <h.minghe@gmail.com>
|
||||||
|
|
|
@ -415,8 +415,6 @@ describe('Pretty printing', () => {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
const res = await app.request(urlString({ query: '{test}' }))
|
|
||||||
|
|
||||||
// TODO enable this
|
// TODO enable this
|
||||||
// expect(await res.text()).toEqual(
|
// expect(await res.text()).toEqual(
|
||||||
// [
|
// [
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
specifiedRules,
|
specifiedRules,
|
||||||
getOperationAST,
|
getOperationAST,
|
||||||
GraphQLError,
|
GraphQLError,
|
||||||
} from 'https://cdn.skypack.dev/graphql@16.5.0?dts'
|
} from 'https://cdn.skypack.dev/graphql@16.6.0?dts'
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
GraphQLSchema,
|
GraphQLSchema,
|
||||||
|
@ -15,16 +15,16 @@ import type {
|
||||||
ValidationRule,
|
ValidationRule,
|
||||||
FormattedExecutionResult,
|
FormattedExecutionResult,
|
||||||
GraphQLFormattedError,
|
GraphQLFormattedError,
|
||||||
} from 'https://cdn.skypack.dev/graphql@16.5.0?dts'
|
} from 'https://cdn.skypack.dev/graphql@16.6.0?dts'
|
||||||
|
|
||||||
import type { Context } from 'https://deno.land/x/hono/mod.ts'
|
import type { Context } from 'https://deno.land/x/hono@v2.7.5/mod.ts'
|
||||||
import { parseBody } from './parse-body.ts'
|
import { parseBody } from './parse-body.ts'
|
||||||
|
|
||||||
export type RootResolver = (ctx?: Context) => Promise<unknown> | unknown
|
export type RootResolver = (ctx?: Context) => Promise<unknown> | unknown
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
schema: GraphQLSchema
|
schema: GraphQLSchema
|
||||||
rootResolver?: RootResolver,
|
rootResolver?: RootResolver
|
||||||
pretty?: boolean
|
pretty?: boolean
|
||||||
validationRules?: ReadonlyArray<ValidationRule>
|
validationRules?: ReadonlyArray<ValidationRule>
|
||||||
// graphiql?: boolean
|
// graphiql?: boolean
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { buildSchema } from 'https://cdn.skypack.dev/graphql@16.5.0?dts'
|
import { buildSchema } from 'https://cdn.skypack.dev/graphql@16.6.0?dts'
|
||||||
import { Hono } from 'https://deno.land/x/hono@v2.6.1/mod.ts'
|
|
||||||
import { graphqlServer } from '../deno_dist/index.ts'
|
|
||||||
import { assertEquals } from 'https://deno.land/std@0.149.0/testing/asserts.ts'
|
import { assertEquals } from 'https://deno.land/std@0.149.0/testing/asserts.ts'
|
||||||
|
import { Hono } from 'https://deno.land/x/hono@v2.7.5/mod.ts'
|
||||||
|
import { graphqlServer } from '../deno_dist/index.ts'
|
||||||
|
|
||||||
Deno.test('graphql-server', async (t) => {
|
Deno.test('graphql-server', async (t) => {
|
||||||
// Construct a schema, using GraphQL schema language
|
// Construct a schema, using GraphQL schema language
|
||||||
|
|
|
@ -1,7 +1 @@
|
||||||
module.exports = {
|
module.exports = require('../../jest.config.js')
|
||||||
testMatch: ['**/test/**/*.+(ts|tsx|js)', '**/src/**/(*.)+(spec|test).+(ts|tsx|js)'],
|
|
||||||
transform: {
|
|
||||||
'^.+\\.(ts|tsx)$': 'ts-jest',
|
|
||||||
},
|
|
||||||
testEnvironment: 'miniflare',
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "@honojs/graphql-server",
|
"name": "@hono/graphql-server",
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
"repository": "git@github.com:honojs/grahql-server.git",
|
"repository": "git@github.com:honojs/grahql-server.git",
|
||||||
"author": "Minghe Huang <h.minghe@gmail.com>",
|
"author": "Minghe Huang <h.minghe@gmail.com>",
|
||||||
|
@ -20,15 +20,12 @@
|
||||||
"test:bun": "bun wiptest bun_test/index.test.ts",
|
"test:bun": "bun wiptest bun_test/index.test.ts",
|
||||||
"test:all": "yarn test && yarn test:deno && yarn test:bun",
|
"test:all": "yarn test && yarn test:deno && yarn test:bun",
|
||||||
"denoify": "rimraf deno_dist && denoify && rimraf 'deno_dist/**/*.test.ts'",
|
"denoify": "rimraf deno_dist && denoify && rimraf 'deno_dist/**/*.test.ts'",
|
||||||
"build": "rimraf dist && tsc --project tsconfig.build.json",
|
"build": "rimraf dist && tsc",
|
||||||
"lint": "eslint --ext js,ts src .eslintrc.js",
|
"lint": "eslint --ext js,ts src .eslintrc.js",
|
||||||
"lint:fix": "eslint --ext js,ts src .eslintrc.js --fix",
|
"lint:fix": "eslint --ext js,ts src .eslintrc.js --fix",
|
||||||
"prerelease": "yarn build && yarn denoify && yarn test:all",
|
"prerelease": "yarn build && yarn denoify && yarn test:all",
|
||||||
"release": "np"
|
"release": "np"
|
||||||
},
|
},
|
||||||
"denoify": {
|
|
||||||
"replacer": "dist/replacer.js"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"hono": "^2.6.1"
|
"hono": "^2.6.1"
|
||||||
},
|
},
|
||||||
|
@ -40,7 +37,7 @@
|
||||||
"@types/jest": "^28.1.4",
|
"@types/jest": "^28.1.4",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
||||||
"@typescript-eslint/parser": "^5.21.0",
|
"@typescript-eslint/parser": "^5.21.0",
|
||||||
"denoify": "^1.4.5",
|
"denoify": "^1.4.9",
|
||||||
"eslint": "^8.14.0",
|
"eslint": "^8.14.0",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-define-config": "^1.4.0",
|
"eslint-define-config": "^1.4.0",
|
||||||
|
@ -59,6 +56,6 @@
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=11.0.0"
|
"node": ">=16.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,7 +24,7 @@ export type RootResolver = (ctx?: Context) => Promise<unknown> | unknown
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
schema: GraphQLSchema
|
schema: GraphQLSchema
|
||||||
rootResolver?: RootResolver,
|
rootResolver?: RootResolver
|
||||||
pretty?: boolean
|
pretty?: boolean
|
||||||
validationRules?: ReadonlyArray<ValidationRule>
|
validationRules?: ReadonlyArray<ValidationRule>
|
||||||
// graphiql?: boolean
|
// graphiql?: boolean
|
||||||
|
|
|
@ -7,8 +7,8 @@ import {
|
||||||
} from 'graphql'
|
} from 'graphql'
|
||||||
import { Hono } from 'hono'
|
import { Hono } from 'hono'
|
||||||
import type { Context, Next } from 'hono'
|
import type { Context, Next } from 'hono'
|
||||||
import { errorMessages, graphqlServer } from '.'
|
import { errorMessages, graphqlServer } from '../src'
|
||||||
import type { RootResolver } from './index'
|
import type { RootResolver } from '../src'
|
||||||
|
|
||||||
// Do not show `console.error` messages
|
// Do not show `console.error` messages
|
||||||
jest.spyOn(console, 'error').mockImplementation()
|
jest.spyOn(console, 'error').mockImplementation()
|
||||||
|
@ -79,12 +79,12 @@ describe('GraphQL Middleware - Simple way', () => {
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
const rootResolver: RootResolver = (ctx?: Context) => {
|
const rootResolver: RootResolver = (ctx?: Context) => {
|
||||||
const name = ctx?.get('name')
|
const name = ctx?.get('name')
|
||||||
return {
|
return {
|
||||||
hi: `hi ${name}`
|
hi: `hi ${name}`,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
|
|
||||||
|
@ -93,7 +93,6 @@ describe('GraphQL Middleware - Simple way', () => {
|
||||||
await next()
|
await next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
'/graphql',
|
'/graphql',
|
||||||
graphqlServer({
|
graphqlServer({
|
|
@ -1,4 +1,4 @@
|
||||||
import { parseBody } from './parse-body'
|
import { parseBody } from '../src/parse-body'
|
||||||
|
|
||||||
describe('parseBody', () => {
|
describe('parseBody', () => {
|
||||||
it('Should return a blank JSON object', async () => {
|
it('Should return a blank JSON object', async () => {
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"extends": "./tsconfig.json",
|
|
||||||
"include": [
|
|
||||||
"src/**/*.ts"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"src/deno/**/*.ts",
|
|
||||||
"src/**/*.test.ts"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,20 +1,10 @@
|
||||||
{
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2020",
|
|
||||||
"module": "commonjs",
|
|
||||||
"declaration": true,
|
|
||||||
"moduleResolution": "Node",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"strictPropertyInitialization": true,
|
|
||||||
"strictNullChecks": true,
|
|
||||||
"noUnusedLocals": true,
|
|
||||||
"noUnusedParameters": true,
|
|
||||||
"types": ["jest", "node", "@cloudflare/workers-types"],
|
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
"outDir": "./dist"
|
"outDir": "./dist",
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts"]
|
"include": [
|
||||||
}
|
"src/**/*.ts"
|
||||||
|
],
|
||||||
|
}
|
|
@ -15,6 +15,5 @@
|
||||||
"node",
|
"node",
|
||||||
"@cloudflare/workers-types"
|
"@cloudflare/workers-types"
|
||||||
],
|
],
|
||||||
},
|
}
|
||||||
"include": [],
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue