Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tooling #169

Merged
merged 5 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Use Node.js LTS
uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: '20.x'
- uses: bahmutov/npm-install@v1
with:
install-command: yarn --immutable
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib
dist
node_modules
.nvmrc
.nyc_output
Expand Down
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ install: package.json ## Install dependencies
@$(PKG) install

watch: ## continuously compile ES6 files to JS
NODE_ENV=development ./node_modules/.bin/webpack --watch
@yarn vite build --watch

test: ## Launch unit tests
@NODE_ENV=test ./node_modules/.bin/jest
@NODE_ENV=test NODE_OPTIONS="$$NODE_OPTIONS --experimental-vm-modules" ./node_modules/.bin/jest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this I don't understand. Would you ind explaining what it does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make jest accept our ESM code: https://jestjs.io/docs/ecmascript-modules

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean that, in order to use the CLI, our users will have to use the same flag? This would be a BC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, as said in the PR desc, I tested the CLI. I did it without any flag on latest Node LTS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minimum required node version is 16.


watch-test: ## Launch unit tests and watch for changes
@NODE_ENV=test ./node_modules/.bin/jest --watch
@NODE_ENV=test NODE_OPTIONS="$$NODE_OPTIONS --experimental-vm-modules" ./node_modules/.bin/jest --watch

format: ## Format the source code
@./node_modules/.bin/eslint --fix ./src
Expand All @@ -25,4 +25,4 @@ run: ## Launch server with example data
@node ./bin/json-graphql-server.js example/data.js

build: ## Build production release
@NODE_ENV=production ./node_modules/.bin/webpack
@yarn vite build
38 changes: 0 additions & 38 deletions babel.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions bin/json-graphql-server.js → bin/json-graphql-server.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require('reify');
var path = require('path');
var express = require('express');
var cors = require('cors');
var JsonGraphqlServer = require('../lib/json-graphql-server.node.min').default;
var JsonGraphqlServer = require('../dist/json-graphql-server').default;
fzaninotto marked this conversation as resolved.
Show resolved Hide resolved

var dataFilePath = process.argv.length > 2 ? process.argv[2] : './data.json';
var data = require(path.join(process.cwd(), dataFilePath));
Expand All @@ -23,7 +23,7 @@ process.argv.forEach((arg, index) => {
});

app.use(cors());
app.use('/', JsonGraphqlServer(data));
app.use('/', JsonGraphqlServer({ data }).getHandler());
djhi marked this conversation as resolved.
Show resolved Hide resolved
app.listen(PORT, HOST);
var msg = `GraphQL server running with your data at http://${HOST}:${PORT}/`;
console.log(msg); // eslint-disable-line no-console
Expand Down
61 changes: 30 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"name": "json-graphql-server",
"version": "2.4.1",
"main": "lib/json-graphql-server.node.min.js",
"browser": "lib/json-graphql-server.client.min.js",
"type": "module",
"main": "./dist/json-graphql-server.umd.cjs",
"module": "./dist/json-graphql-server.js",
"exports": {
".": {
"import": "./dist/json-graphql-server.js",
"require": "./dist/json-graphql-server.umd.cjs"
}
},
"repository": "[email protected]:marmelab/json-graphql-server.git",
"authors": [
"François Zaninotto",
Expand Down Expand Up @@ -30,42 +37,34 @@
]
},
"devDependencies": {
"@babel/cli": "^7.6.3",
"@babel/core": "^7.6.3",
"@babel/plugin-external-helpers": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.6.3",
"@types/jest": "^25.2.1",
"@types/jest": "^29.5.12",
"babel-eslint": "^10.0.3",
"babel-jest": "^25.4.0",
"babel-loader": "^8.0.6",
"babel-plugin-add-module-exports": "^1.0.2",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.1",
"husky": "^4.2.5",
"jest": "^25.4.0",
"lint-staged": "^10.1.7",
"prettier": "^2.0.5",
"supertest": "^4.0.2",
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9"
"babel-jest": "^29.7.0",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.2.0",
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"supertest": "^6.3.4",
"vite": "^5.2.8"
},
"dependencies": {
"@apollo/client": "^3.9.11",
"cors": "^2.8.4",
"express": "^4.17.2",
"@graphql-tools/schema": "^10.0.3",
"cors": "^2.8.5",
"express": "^4.17.3",
"express-graphql": "^0.9.0",
"graphql": "^14.5.8",
"graphql-tag": "^2.10.1",
"graphql-tools": "^4.0.5",
"graphql-type-json": "^0.3.0",
"inflection": "^1.12.0",
"graphql": "^16.8.1",
"graphql-tag": "^2.12.6",
"graphql-type-json": "^0.3.2",
"inflection": "^3.0.0",
"lodash.merge": "^4.6.2",
"reify": "^0.20.12",
"xhr-mock": "^2.5.0"
"xhr-mock": "^2.5.1"
},
"bin": {
"json-graphql-server": "bin/json-graphql-server.js"
Expand Down
109 changes: 35 additions & 74 deletions src/introspection/getSchemaFromData.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GraphQLString,
} from 'graphql';
import getSchemaFromData from './getSchemaFromData';
import e from 'cors';
fzaninotto marked this conversation as resolved.
Show resolved Hide resolved

const data = {
posts: [
Expand Down Expand Up @@ -128,12 +129,10 @@ test('creates three query fields per data type', () => {
const queries = getSchemaFromData(data).getQueryType().getFields();
expect(queries['Post'].type.name).toEqual(PostType.name);
expect(queries['Post'].args).toEqual([
{
defaultValue: undefined,
description: null,
expect.objectContaining({
name: 'id',
type: new GraphQLNonNull(GraphQLID),
},
}),
]);
expect(queries['allPosts'].type.toString()).toEqual('[Post]');
expect(queries['allPosts'].args[0].name).toEqual('page');
Expand All @@ -150,12 +149,10 @@ test('creates three query fields per data type', () => {

expect(queries['User'].type.name).toEqual(UserType.name);
expect(queries['User'].args).toEqual([
{
defaultValue: undefined,
description: null,
expect.objectContaining({
name: 'id',
type: new GraphQLNonNull(GraphQLID),
},
}),
]);
expect(queries['allUsers'].type.toString()).toEqual('[User]');
expect(queries['allUsers'].args[0].name).toEqual('page');
Expand All @@ -175,93 +172,69 @@ test('creates three mutation fields per data type', () => {
const mutations = getSchemaFromData(data).getMutationType().getFields();
expect(mutations['createPost'].type.name).toEqual(PostType.name);
expect(mutations['createPost'].args).toEqual([
{
expect.objectContaining({
name: 'title',
type: new GraphQLNonNull(GraphQLString),
defaultValue: undefined,
description: null,
},
{
}),
expect.objectContaining({
name: 'views',
type: new GraphQLNonNull(GraphQLInt),
defaultValue: undefined,
description: null,
},
{
}),
expect.objectContaining({
name: 'user_id',
type: new GraphQLNonNull(GraphQLID),
defaultValue: undefined,
description: null,
},
}),
]);
expect(mutations['updatePost'].type.name).toEqual(PostType.name);
expect(mutations['updatePost'].args).toEqual([
{
expect.objectContaining({
name: 'id',
type: new GraphQLNonNull(GraphQLID),
defaultValue: undefined,
description: null,
},
{
}),
expect.objectContaining({
name: 'title',
type: GraphQLString,
defaultValue: undefined,
description: null,
},
{
}),
expect.objectContaining({
name: 'views',
type: GraphQLInt,
defaultValue: undefined,
description: null,
},
{
}),
expect.objectContaining({
name: 'user_id',
type: GraphQLID,
defaultValue: undefined,
description: null,
},
}),
]);
expect(mutations['removePost'].type.name).toEqual(PostType.name);
expect(mutations['removePost'].args).toEqual([
{
expect.objectContaining({
name: 'id',
type: new GraphQLNonNull(GraphQLID),
defaultValue: undefined,
description: null,
},
}),
]);
expect(mutations['createUser'].type.name).toEqual(UserType.name);
expect(mutations['createUser'].args).toEqual([
{
expect.objectContaining({
name: 'name',
type: new GraphQLNonNull(GraphQLString),
defaultValue: undefined,
description: null,
},
}),
]);
expect(mutations['updateUser'].type.name).toEqual(UserType.name);
expect(mutations['updateUser'].args).toEqual([
{
expect.objectContaining({
name: 'id',
type: new GraphQLNonNull(GraphQLID),
defaultValue: undefined,
description: null,
},
{
}),
expect.objectContaining({
name: 'name',
type: GraphQLString,
defaultValue: undefined,
description: null,
},
}),
]);
expect(mutations['removeUser'].type.name).toEqual(UserType.name);
expect(mutations['removeUser'].args).toEqual([
{
defaultValue: undefined,
description: null,
expect.objectContaining({
name: 'id',
type: new GraphQLNonNull(GraphQLID),
},
}),
]);
});

Expand All @@ -270,30 +243,18 @@ test('creates the mutation *Input type for createMany', () => {
const createManyPostInputType = mutations['createManyPost'].args[0].type;
expect(createManyPostInputType.toString()).toEqual('[PostInput]');
expect(createManyPostInputType.ofType.getFields()).toEqual({
title: {
title: expect.objectContaining({
type: new GraphQLNonNull(GraphQLString),
name: 'title',
astNode: undefined,
defaultValue: undefined,
description: undefined,
extensions: undefined,
},
views: {
}),
views: expect.objectContaining({
type: new GraphQLNonNull(GraphQLInt),
name: 'views',
astNode: undefined,
defaultValue: undefined,
description: undefined,
extensions: undefined,
},
user_id: {
}),
user_id: expect.objectContaining({
type: new GraphQLNonNull(GraphQLID),
name: 'user_id',
astNode: undefined,
defaultValue: undefined,
description: undefined,
extensions: undefined,
},
}),
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/schemaBuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeExecutableSchema } from 'graphql-tools';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { printSchema } from 'graphql';
import getSchemaFromData from './introspection/getSchemaFromData';
import resolver from './resolver';
Expand Down
Loading
Loading