Skip to content

Commit

Permalink
Update feTS, Bob and fix redirection issues (#1390)
Browse files Browse the repository at this point in the history
* Update feTS, Bob and fix redirection issues

* chore(dependencies): updated changesets for modified dependencies

* Fix tests

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ardatan and github-actions[bot] committed Nov 23, 2023
1 parent 182bec2 commit 03b0ccf
Show file tree
Hide file tree
Showing 19 changed files with 555 additions and 1,295 deletions.
6 changes: 6 additions & 0 deletions .changeset/sofa-api-1390-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'sofa-api': patch
---
dependencies updates:
- Updated dependency [`@whatwg-node/fetch@^0.9.14` ↗︎](https://www.npmjs.com/package/@whatwg-node/fetch/v/0.9.14) (from `^0.9.0`, in `dependencies`)
- Updated dependency [`fets@^0.6.4` ↗︎](https://www.npmjs.com/package/fets/v/0.6.4) (from `^0.2.0`, in `dependencies`)
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [16, 18]
node_version: [18, 20, 21]
steps:
- uses: actions/checkout@master
- name: Use Node.js ${{ matrix.node_version }}
Expand All @@ -25,8 +25,6 @@ jobs:
run: yarn build
- name: Test
run: yarn test
- name: Bundle Size
run: yarn bundlesize
- name: Publish Canary
env: # Or as an environment variable
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ package-lock.json
.next
.idea/
website/public/sitemap.xml
.bob/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
website/algolia-lockfile.json
.bob
File renamed without changes.
4 changes: 2 additions & 2 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const yoga = createYoga({
});

app.route({
path: '/graphql',
handler: yoga,
path: yoga.graphqlEndpoint,
handler: yoga as any,
})

const port = 4000;
Expand Down
4 changes: 1 addition & 3 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs"
}
"include": ["example/index.ts"]
}
5 changes: 5 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
testEnvironment: 'node',
modulePathIgnorePatterns: ['<rootDir>/dist'],
resolver: 'bob-the-bundler/jest-resolver',
};
3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@
"name": "sofa-api",
"description": "Create REST APIs with GraphQL",
"version": "0.18.0",
"type": "module",
"buildOptions": {
"input": "./src/index.ts"
},
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.mjs",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"require": {
"types": "./dist/typings/index.d.cts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/*.mjs"
}
"./package.json": "./package.json"
},
"typings": "dist/index.d.ts",
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
"definition": "dist/typings/index.d.ts"
},
"license": "MIT",
"keywords": [
Expand All @@ -43,16 +51,16 @@
},
"dependencies": {
"@graphql-tools/utils": "^10.0.0",
"@whatwg-node/fetch": "^0.9.0",
"fets": "^0.2.0",
"@whatwg-node/fetch": "^0.9.14",
"fets": "^0.6.4",
"ansi-colors": "^4.1.3",
"openapi-types": "^12.1.0",
"param-case": "^3.0.4",
"title-case": "^3.0.3",
"tslib": "^2.5.0"
},
"scripts": {
"start": "ts-node --project tsconfig.example.json example/index.ts",
"start": "cd example && tsup-node index.ts && mv dist/index.js dist/index.cjs && node dist/index.cjs",
"clean": "rm -rf dist",
"prebuild": "yarn clean",
"build": "bob build --single",
Expand All @@ -73,8 +81,7 @@
"@types/swagger-ui-dist": "3.30.1",
"@types/yamljs": "0.2.31",
"babel-jest": "29.5.0",
"bob-the-bundler": "1.7.3",
"bundlesize": "0.18.1",
"bob-the-bundler": "7.0.1",
"chalk": "^4",
"graphql": "16.6.0",
"graphql-scalars": "1.22.0",
Expand All @@ -85,7 +92,7 @@
"prettier": "2.8.8",
"swagger-ui-dist": "4.18.3",
"ts-jest": "29.1.0",
"ts-node": "10.9.1",
"tsup": "8.0.1",
"typescript": "5.0.4"
},
"husky": {
Expand All @@ -101,12 +108,5 @@
"publishConfig": {
"directory": "dist",
"access": "public"
},
"bundlesize": [
{
"path": "./dist/index.mjs",
"maxSize": "40 kB",
"compression": "none"
}
]
}
}
6 changes: 3 additions & 3 deletions src/ast.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
getOperationAST,
DocumentNode,
OperationDefinitionNode,
VariableDefinitionNode,
type DocumentNode,
type OperationDefinitionNode,
type VariableDefinitionNode,
} from 'graphql';

export type OperationInfo =
Expand Down
8 changes: 4 additions & 4 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
VariableDefinitionNode,
GraphQLSchema,
TypeNode,
type VariableDefinitionNode,
type GraphQLSchema,
type TypeNode,
isScalarType,
isEqualType,
GraphQLBoolean,
isInputObjectType,
Kind,
} from 'graphql';
import { isNil } from './common';
import { isNil } from './common.js';

export function parseVariable({
value,
Expand Down
38 changes: 19 additions & 19 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ import {
isInputObjectType,
} from 'graphql';
import { buildOperationNodeForField, createGraphQLError } from '@graphql-tools/utils';
import { getOperationInfo, OperationInfo } from './ast';
import type { Sofa, Route } from './sofa';
import type { RouteInfo, DefaultSofaServerContext } from './types';
import { getOperationInfo, OperationInfo } from './ast.js';
import type { Sofa, Route } from './sofa.js';
import type { RouteInfo, DefaultSofaServerContext } from './types.js';
import { convertName } from './common';
import { parseVariable } from './parse';
import { StartSubscriptionEvent, SubscriptionManager } from './subscriptions';
import { logger } from './logger';
import { parseVariable } from './parse.js';
import { type StartSubscriptionEvent, SubscriptionManager } from './subscriptions.js';
import { logger } from './logger.js';
import {
Response,
createRouter as createRouterInstance,
RouterRequest,
Router,
RouteHandler,
RouteSchemas,
type RouterRequest,
type Router,
type RouteHandler,
type RouteSchemas,
} from 'fets';
import { HTTPMethod, StatusCode } from 'fets/typings/typed-fetch';
import { isInPath, resolveParamSchema, resolveRequestBody, resolveResponse, resolveVariableDescription } from './open-api/operations';
import { buildSchemaObjectFromType } from './open-api/types';
import type { HTTPMethod, StatusCode } from 'fets/typings/typed-fetch';
import { isInPath, resolveParamSchema, resolveRequestBody, resolveResponse, resolveVariableDescription } from './open-api/operations.js';
import { buildSchemaObjectFromType } from './open-api/types.js';

export type ErrorHandler = (errors: ReadonlyArray<any>) => Response;

Expand All @@ -40,7 +40,6 @@ declare module 'graphql' {
}
}


const defaultErrorHandler: ErrorHandler = (errors) => {
let status: StatusCode | undefined;
const headers: Record<string, string> = {
Expand Down Expand Up @@ -110,6 +109,7 @@ export function createRouter(sofa: Sofa) {
base: sofa.basePath,
openAPI: sofa.openAPI,
swaggerUI: sofa.swaggerUI,
landingPage: false,
});

const queryType = sofa.schema.getQueryType();
Expand Down Expand Up @@ -150,7 +150,7 @@ export function createRouter(sofa: Sofa) {
} catch (error) {
return Response.json(error, {
status: 500,
statusText: 'Subscription failed',
statusText: 'Subscription failed' as any,
});
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ export function createRouter(sofa: Sofa) {
} catch (error) {
return Response.json(error, {
status: 500,
statusText: 'Subscription failed to update',
statusText: 'Subscription failed to update' as any,
});
}
}
Expand All @@ -196,7 +196,7 @@ export function createRouter(sofa: Sofa) {
} catch (error) {
return Response.json(error, {
status: 500,
statusText: 'Subscription failed to stop',
statusText: 'Subscription failed to stop' as any,
});
}
}
Expand Down Expand Up @@ -468,9 +468,9 @@ function useHandler(config: {
})
}

const sofaContext: DefaultSofaServerContext = Object.assign(serverContext, {
const sofaContext = Object.assign(serverContext, {
request,
});
}) as DefaultSofaServerContext;
const contextValue = await sofa.contextFactory(sofaContext);
const result = await sofa.execute({
schema: sofa.schema,
Expand Down
12 changes: 6 additions & 6 deletions src/sofa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
execute,
} from 'graphql';

import { Ignore, ContextFn, ContextValue } from './types';
import { convertName } from './common';
import { logger } from './logger';
import { ErrorHandler } from './router';
import { HTTPMethod, StatusCode } from 'fets/typings/typed-fetch';
import { RouterOpenAPIOptions, RouterSwaggerUIOptions } from 'fets';
import type { Ignore, ContextFn, ContextValue } from './types.js';
import { convertName } from './common.js';
import { logger } from './logger.js';
import type { ErrorHandler } from './router.js';
import type { HTTPMethod, StatusCode } from 'fets/typings/typed-fetch';
import type { RouterOpenAPIOptions, RouterSwaggerUIOptions } from 'fets';

// user passes:
// - schema
Expand Down
18 changes: 9 additions & 9 deletions src/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
DocumentNode,
VariableDefinitionNode,
ExecutionResult,
type DocumentNode,
type VariableDefinitionNode,
type ExecutionResult,
Kind,
OperationTypeNode,
type OperationTypeNode,
} from 'graphql';
import { fetch, crypto } from '@whatwg-node/fetch';
import { buildOperationNodeForField } from '@graphql-tools/utils';
import type { ContextValue } from './types';
import type { Sofa } from './sofa';
import { getOperationInfo } from './ast';
import { parseVariable } from './parse';
import { logger } from './logger';
import type { ContextValue } from './types.js';
import type { Sofa } from './sofa.js';
import { getOperationInfo } from './ast.js';
import { parseVariable } from './parse.js';
import { logger } from './logger.js';

function isAsyncIterable(obj: any): obj is AsyncIterable<any> {
return typeof obj[Symbol.asyncIterator] === 'function';
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTTPMethod } from 'fets/typings/typed-fetch';
import { DocumentNode } from 'graphql';
import type { HTTPMethod } from 'fets/typings/typed-fetch';
import type { DocumentNode } from 'graphql';

export type ContextValue = Record<string, any>;

Expand Down
7 changes: 0 additions & 7 deletions tsconfig.example.json

This file was deleted.

7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"module": "esnext",
"target": "es2021",
"lib": ["esnext"],
"rootDir": ".",
"moduleResolution": "node",
"sourceMap": true,
"inlineSources": true,
"sourceMap": false,
"declaration": true,
"strict": true,
"noUnusedLocals": true,
Expand All @@ -16,5 +16,6 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"]
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
Loading

0 comments on commit 03b0ccf

Please sign in to comment.