Skip to content

Commit

Permalink
feat: Bump apollo to v4 (#40)
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
danLDev authored Jul 19, 2023
1 parent e957a57 commit 9f0ef97
Show file tree
Hide file tree
Showing 19 changed files with 2,995 additions and 1,624 deletions.
44 changes: 8 additions & 36 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,21 @@ workflows:
jobs:
- unit-tests:
<<: *not_master
name: node-10
version: '10'
- unit-tests:
<<: *not_master
name: node-12
version: '12'
- unit-tests:
<<: *not_master
name: node-14
version: '14'
name: node-16
version: '16'

master:
jobs:
- unit-tests:
<<: *only_master
name: node-10
version: '10'
- unit-tests:
<<: *only_master
name: node-12
version: '12'
- unit-tests:
<<: *only_master
name: node-14
version: '14'
name: node-16
version: '16'
- publish:
<<: *only_master
version: '14'
version: '16'
context: common-env-vars
requires:
- node-10
- node-12
- node-14
- node-16

nightly:
triggers:
Expand All @@ -60,18 +42,8 @@ workflows:
- nightly:
<<: *only_master
context: common-env-vars
name: nightly-10
version: '10'
- nightly:
<<: *only_master
context: common-env-vars
name: nightly-12
version: '12'
- nightly:
<<: *only_master
context: common-env-vars
name: nightly-14
version: '14'
name: nightly-16
version: '16'

jobs:
unit-tests:
Expand Down
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': ['error', {ignoreRestSiblings: true, args: 'none'}],
'@typescript-eslint/ban-types': 'off',
},
};
2 changes: 1 addition & 1 deletion example-federated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"start": "node lib"
},
"dependencies": {
"typescript": "^3.5.3"
"typescript": "^5.1.6"
}
}
45 changes: 26 additions & 19 deletions example-federated/src/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import Koa = require('koa');
import {ApolloServer} from 'apollo-server-koa';
import {ApolloServer} from '@apollo/server';
import compress = require('koa-compress');
import {buildFederatedSchema} from '@apollo/federation';

import typeDefs from './__generated__/schema';
import ResolverTypes from './ResolverTypes';

import sales from './resolvers/sales';
import saleResolveReference from './resolvers/saleResolveReference';
import saleSeller from './resolvers/saleSeller';
import userSales from './resolvers/userSales';
import userNumberOfSales from './resolvers/userNumberOfSales';

import ResolverContext from './ResolverContext';
import http from 'http';
import {koaMiddleware} from '@as-integrations/koa';
import {ApolloServerPluginDrainHttpServer} from '@apollo/server/plugin/drainHttpServer';
import {buildSubgraphSchema} from '@apollo/subgraph';
import {GraphQLResolverMap} from '@apollo/subgraph/dist/schema-helper';

export const resolvers: ResolverTypes = {
Query: {
Expand All @@ -32,24 +33,30 @@ export const resolvers: ResolverTypes = {
},
};

const graphql = new Koa();
const httpServer = http.createServer(graphql.callback());

const server = new ApolloServer({
schema: buildFederatedSchema({
typeDefs,
resolvers,
} as any),
context: ({ctx}: any) => new ResolverContext(ctx),
playground: {
endpoint: '/graphql',
},
schema: buildSubgraphSchema({
resolvers: resolvers as GraphQLResolverMap<any>,
typeDefs: typeDefs,
}),

plugins: [ApolloServerPluginDrainHttpServer({httpServer})],
});

const graphql = new Koa();
const init = async () => {
await server.start();

graphql.use(compress());
graphql.use(compress());

server.applyMiddleware({
app: graphql,
path: '/',
});
graphql.use(
koaMiddleware(server, {
context: async ({ctx}) => new ResolverContext(ctx),
}),
);
};

init().catch(console.error);

export default graphql;
8 changes: 4 additions & 4 deletions example-federated/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# yarn lockfile v1


typescript@^3.5.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
typescript@^5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"start": "node lib"
},
"dependencies": {
"typescript": "^3.5.3"
"typescript": "^5.1.6"
}
}
2 changes: 1 addition & 1 deletion example/src/graphql/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ generates:
content: |+
/* tslint:disable */
// This file was automatically generated and should not be edited.
import {gql} from 'apollo-server-koa';
import {gql} from 'graphql-tag';
export default gql`
- schema-ast
- add:
Expand Down
37 changes: 20 additions & 17 deletions example/src/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import Koa = require('koa');
import {ApolloServer} from 'apollo-server-koa';
import {ApolloServer} from '@apollo/server';
import compress = require('koa-compress');

import typeDefs from './__generated__/schema';
import ResolverTypes from './ResolverTypes';

import contacts from './resolvers/contacts';
import contactAccounts from './resolvers/contactAccounts';

import GooglePerson from './scalars/GooglePersonScalar';
import TrimmedString from './scalars/TrimmedStringScalar';

import createContact from './mutations/createContact';

import ResolverContext from './ResolverContext';
import http from 'http';
import {koaMiddleware} from '@as-integrations/koa';
import {ApolloServerPluginDrainHttpServer} from '@apollo/server/plugin/drainHttpServer';

const Mutations: ResolverTypes['Mutation'] = {
createContact,
Expand All @@ -31,22 +29,27 @@ export const resolvers: ResolverTypes = {
TrimmedString,
};

const graphql = new Koa();
const httpServer = http.createServer(graphql.callback());

const server = new ApolloServer({
typeDefs,
resolvers: resolvers as any,
context: ({ctx}) => new ResolverContext(ctx),
playground: {
endpoint: '/graphql',
},
resolvers: resolvers,
plugins: [ApolloServerPluginDrainHttpServer({httpServer})],
});

const graphql = new Koa();
const init = async () => {
await server.start();

graphql.use(compress());
graphql.use(compress());

server.applyMiddleware({
app: graphql,
path: '/',
});
graphql.use(
koaMiddleware(server, {
context: async ({ctx}) => new ResolverContext(ctx),
}),
);
};

init().catch(console.error);

export default graphql;
2 changes: 1 addition & 1 deletion example/src/graphql/scalars/GooglePersonScalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function validate(value: any): GooglePerson {

export default new GraphQLScalarType({
name: 'GooglePerson',
serialize(value: GooglePerson | null | undefined): GooglePerson | null | undefined {
serialize(value): GooglePerson | null | undefined {
if (value == null) return null;
return validate(value);
},
Expand Down
8 changes: 4 additions & 4 deletions example/src/graphql/scalars/TrimmedStringScalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export default new GraphQLScalarType({

description: 'A string that will be trimmed when resolved',

serialize(value?: string | null): string | null | undefined {
return value ? value.trim() : value;
serialize(value): string | null | undefined {
return value ? (<string>value).trim() : (value as string | null | undefined);
},

parseLiteral(ast) {
Expand All @@ -19,7 +19,7 @@ export default new GraphQLScalarType({
}
},

parseValue(value?: string | null): string | null | undefined {
return typeof value === 'string' ? value.trim() : value;
parseValue(value): string | null | undefined {
return typeof value === 'string' ? (<string>value).trim() : (value as string | null | undefined);
},
});
8 changes: 4 additions & 4 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# yarn lockfile v1


typescript@^3.5.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
typescript@^5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==
36 changes: 22 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"scripts": {
"build": "tsc",
"lint": "tslint './src/**/*.{ts,tsx}' -t verbose -p .",
"lint": "eslint './src/**/*.{ts,tsx}' --fix",
"prettier:write": "prettier --ignore-path .gitignore --write './**/*.{md,json,yml,js,jsx,ts,tsx}'",
"prettier:check": "prettier --ignore-path .gitignore --list-different './**/*.{md,json,yml,js,jsx,ts,tsx}'",
"test": "yarn test:unit && yarn test:normal && yarn test:federated",
Expand All @@ -32,7 +32,7 @@
"lint-staged": {
"src/**/*.{ts,tsx}": [
"prettier --write",
"tslint -t verbose -p .",
"eslint -c .eslintrc.js",
"git add"
],
"example/**/*.{ts,tsx}": [
Expand All @@ -45,7 +45,7 @@
]
},
"devDependencies": {
"@apollo/federation": "^0.9.4",
"@apollo/server": "^4.7.0",
"@commitlint/cli": "^8.1.0",
"@threads/tsconfig": "^1.0.0",
"@types/babel__code-frame": "^7.0.1",
Expand All @@ -56,8 +56,12 @@
"@types/koa-mount": "^4.0.0",
"@types/mkdirp": "^0.5.2",
"@types/ms": "^0.7.30",
"apollo-server-koa": "^2.14.2",
"graphql": "^14.5.8",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"eslint": "~8.15.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-prettier": "^3.4.0",
"graphql": "^16.6.0",
"husky": "^3.0.4",
"jest": "^24.9.0",
"koa": "^2.8.1",
Expand All @@ -68,23 +72,27 @@
"rimraf": "^3.0.0",
"strip-ansi": "^6.0.0",
"ts-jest": "^24.1.0",
"tslint": "^5.18.0",
"type-assertions": "^1.1.0",
"typescript": "^3.9.6"
"typescript": "^5.1.6",
"@koa/cors": "^4.0.0",
"@types/koa__cors": "^2.2.3"
},
"peerDependencies": {
"apollo-server-koa": "^2.14.2",
"graphql": "^14.4.2"
"graphql": "^16.6.0"
},
"dependencies": {
"@apollo/subgraph": "^2.4.10",
"@as-integrations/koa": "^1.1.1",
"@babel/code-frame": "^7.5.5",
"@graphql-codegen/add": "^1.8.0",
"@graphql-codegen/cli": "^1.8.0",
"@graphql-codegen/schema-ast": "^1.8.0",
"@graphql-codegen/typescript": "^1.8.0",
"@graphql-codegen/typescript-resolvers": "^1.8.0",
"@graphql-codegen/add": "^5.0.0",
"@graphql-codegen/cli": "^4.0.1",
"@graphql-codegen/schema-ast": "^4.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-resolvers": "^4.0.1",
"@types/sane": "^2.0.0",
"chalk": "^3.0.0",
"graphql-tag": "^2.12.6",
"graphql-tools": "4.0.8",
"js-yaml": "^3.13.1",
"mkdirp": "^0.5.1",
"ms": "^2.1.2",
Expand Down
Loading

0 comments on commit 9f0ef97

Please sign in to comment.