Skip to content

Commit

Permalink
Remove deprecated connectors & some cleanup (#1406)
Browse files Browse the repository at this point in the history
* Remove deprecated connectors

* Fix tests

* Fix custom domain

* Fix format

* Fix
  • Loading branch information
ardatan committed Apr 24, 2020
1 parent 604516c commit 2ffad6d
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 483 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Expand Up @@ -51,6 +51,8 @@ jobs:
run: yarn build
- name: Test
run: yarn test --logHeapUsage
env:
CI: true

publish-canary:
name: Publish Canary
Expand Down
14 changes: 4 additions & 10 deletions CONTRIBUTING.md
@@ -1,10 +1,4 @@
# Apollo Contributor Guide

Excited about Apollo and want to make it better? We’re excited too!

Apollo is a community of developers just like you, striving to create the best tools and libraries around GraphQL. We welcome anyone who wants to contribute or provide constructive feedback, no matter the age or level of experience. If you want to help but don't know where to start, let us know, and we'll find something for you.

Oh, and if you haven't already, sign up for the [Apollo Slack](http://www.apollodata.com/#slack).
# GraphQL Tools Contributor Guide

Here are some ways to contribute to the project, from easiest to most difficult:

Expand Down Expand Up @@ -35,15 +29,15 @@ Improving the documentation, examples, and other open source content can be the

### Responding to issues

In addition to reporting issues, a great way to contribute to Apollo is to respond to other peoples' issues and try to identify the problem or help them work around it. If you’re interested in taking a more active role in this process, please go ahead and respond to issues. And don't forget to say "Hi" on Apollo Slack!
In addition to reporting issues, a great way to contribute to GraphQL Tools is to respond to other peoples' issues and try to identify the problem or help them work around it. If you’re interested in taking a more active role in this process, please go ahead and respond to issues.

### Small bug fixes

For a small bug fix change (less than 20 lines of code changed), feel free to open a pull request. We’ll try to merge it as fast as possible and ideally publish a new release on the same day. The only requirement is, make sure you also add a test that verifies the bug you are trying to fix.

### Suggesting features

Most of the features in Apollo came from suggestions by you, the community! We welcome any ideas about how to make Apollo better for your use case. Unless there is overwhelming demand for a feature, it might not get implemented immediately, but please include as much information as possible that will help people have a discussion about your proposal:
Most of the features in GraphQL Tools came from suggestions by you, the community! We welcome any ideas about how to make GraphQL Tools better for your use case. Unless there is overwhelming demand for a feature, it might not get implemented immediately, but please include as much information as possible that will help people have a discussion about your proposal:

1. **Use case:** What are you trying to accomplish, in specific terms? Often, there might already be a good way to do what you need and a new feature is unnecessary, but it’s hard to know without information about the specific use case.
2. **Could this be a plugin?** In many cases, a feature might be too niche to be included in the core of a library, and is better implemented as a companion package. If there isn’t a way to extend the library to do what you want, could we add additional plugin APIs? It’s important to make the case for why a feature should be part of the core functionality of the library.
Expand Down Expand Up @@ -72,7 +66,7 @@ For significant changes to a repository, it’s important to settle on a design

### Code review guidelines

It’s important that every piece of code in Apollo packages is reviewed by at least one core contributor familiar with that codebase. Here are some things we look for:
It’s important that every piece of code in GraphQL Tools packages is reviewed by at least one core contributor familiar with that codebase. Here are some things we look for:

1. **Required CI checks pass.** This is a prerequisite for the review, and it is the PR author's responsibility. As long as the tests don’t pass, the PR won't get reviewed.
2. **Simplicity.** Is this the simplest way to achieve the intended goal? If there are too many files, redundant functions, or complex lines of code, suggest a simpler way to do the same thing. In particular, avoid implementing an overly general solution when a simple, small, and pragmatic fix will do.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 - 2017 Meteor Development Group, Inc.
Copyright (c) 2020 The Guild, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 3 additions & 1 deletion jest.config.js
@@ -1,4 +1,6 @@
const { resolve } = require('path');
/* eslint-disable no-implicit-coercion */
/* eslint-disable import/no-commonjs */
/* eslint-disable import/unambiguous */
const CI = !!process.env.CI;

module.exports = {
Expand Down
6 changes: 0 additions & 6 deletions netlify.toml

This file was deleted.

14 changes: 5 additions & 9 deletions package.json
Expand Up @@ -47,13 +47,11 @@
},
"homepage": "https://github.com/ardatan/graphql-tools#readme",
"dependencies": {
"apollo-link": "^1.2.14",
"apollo-upload-client": "^13.0.0",
"deprecated-decorator": "^0.1.6",
"form-data": "^3.0.0",
"node-fetch": "^2.6.0",
"tslib": "^1.11.1",
"uuid": "^7.0.3"
"apollo-link": "1.2.14",
"apollo-upload-client": "13.0.0",
"form-data": "3.0.0",
"cross-fetch": "3.0.4",
"tslib": "1.11.1"
},
"peerDependencies": {
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
Expand All @@ -66,8 +64,6 @@
"@types/graphql-upload": "8.0.3",
"@types/jest": "25.2.1",
"@types/node": "13.13.2",
"@types/node-fetch": "2.5.7",
"@types/uuid": "7.0.3",
"@typescript-eslint/eslint-plugin": "2.29.0",
"@typescript-eslint/parser": "2.29.0",
"apollo-errors": "1.9.0",
Expand Down
12 changes: 8 additions & 4 deletions rollup.config.js
@@ -1,9 +1,13 @@
/* eslint-disable import/no-nodejs-modules */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/no-anonymous-default-export */
import { join, dirname, basename } from 'path';
import { copyFileSync } from 'fs';

import autoExternal from 'rollup-plugin-auto-external';
import resolveNode from '@rollup/plugin-node-resolve';
import generatePackageJson from 'rollup-plugin-generate-package-json';
import rollupTypescript from 'rollup-plugin-typescript2';
import path from 'path';
import fs from 'fs';

const commonOutputOptions = {
preferConst: true,
Expand Down Expand Up @@ -77,10 +81,10 @@ function copyFiles(paths) {
return {
name: 'copy-files',
generateBundle(outputOptions) {
const outputPath = outputOptions.dir || path.dirname(outputOptions.file);
const outputPath = outputOptions.dir || dirname(outputOptions.file);

paths.forEach((file) => {
fs.copyFileSync(file, path.join(outputPath, path.basename(file)));
copyFileSync(file, join(outputPath, basename(file)));
});
},
};
Expand Down
11 changes: 0 additions & 11 deletions src/Interfaces.ts
Expand Up @@ -361,20 +361,9 @@ export interface ILogger {
log: (error: Error) => void;
}

export type IConnectorCls<TContext = any> = new (context?: TContext) => any;

export type IConnectorFn<TContext = any> = (context?: TContext) => any;

export type IConnector<TContext = any> =
| IConnectorCls<TContext>
| IConnectorFn<TContext>;

export type IConnectors<TContext = any> = Record<string, IConnector<TContext>>;

export interface IExecutableSchemaDefinition<TContext = any> {
typeDefs: ITypeDefinitions;
resolvers?: IResolvers<any, TContext> | Array<IResolvers<any, TContext>>;
connectors?: IConnectors<TContext>;
logger?: ILogger;
allowUndefinedInResolve?: boolean;
resolverValidationOptions?: IResolverValidationOptions;
Expand Down
1 change: 1 addition & 0 deletions src/declarations.d.ts
Expand Up @@ -8,3 +8,4 @@ interface ReadonlyArray<T> {
interface Array<T> {
reduce<R>(reducer: Reducer<T, R>, target: Partial<R>): R;
}
declare module 'apollo-upload-client';
73 changes: 0 additions & 73 deletions src/generate/attachConnectorsToContext.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/generate/index.ts
Expand Up @@ -2,7 +2,6 @@ export { default as addResolversToSchema } from './addResolversToSchema';
export { default as addSchemaLevelResolver } from './addSchemaLevelResolver';
export { default as assertResolversPresent } from './assertResolversPresent';
export { default as attachDirectiveResolvers } from './attachDirectiveResolvers';
export { default as attachConnectorsToContext } from './attachConnectorsToContext';
export { default as buildSchemaFromTypeDefinitions } from './buildSchemaFromTypeDefinitions';
export { chainResolvers } from './chainResolvers';
export { default as checkForResolveTypeResolver } from './checkForResolveTypeResolver';
Expand Down
8 changes: 0 additions & 8 deletions src/generate/makeExecutableSchema.ts
Expand Up @@ -12,7 +12,6 @@ import { SchemaDirectiveVisitor, forEachField } from '../utils/index';
import attachDirectiveResolvers from './attachDirectiveResolvers';
import assertResolversPresent from './assertResolversPresent';
import addResolversToSchema from './addResolversToSchema';
import attachConnectorsToContext from './attachConnectorsToContext';
import addSchemaLevelResolver from './addSchemaLevelResolver';
import buildSchemaFromTypeDefinitions from './buildSchemaFromTypeDefinitions';
import decorateWithLogger from './decorateWithLogger';
Expand All @@ -21,7 +20,6 @@ import SchemaError from './SchemaError';
export function makeExecutableSchema<TContext = any>({
typeDefs,
resolvers = {},
connectors,
logger,
allowUndefinedInResolve = true,
resolverValidationOptions = {},
Expand Down Expand Up @@ -78,12 +76,6 @@ export function makeExecutableSchema<TContext = any>({
);
}

if (connectors != null) {
// connectors are optional, at least for now. That means you can just import them in the resolve
// function if you want.
attachConnectorsToContext(schema, connectors);
}

if (directiveResolvers != null) {
attachDirectiveResolvers(schema, directiveResolvers);
}
Expand Down
2 changes: 1 addition & 1 deletion src/links/createServerHttpLink.ts
Expand Up @@ -5,7 +5,7 @@ import {
isExtractableFile,
} from 'apollo-upload-client';
import FormData, { AppendOptions } from 'form-data';
import fetch from 'node-fetch';
import { fetch } from 'cross-fetch';

import { AwaitVariablesLink } from './AwaitVariablesLink';

Expand Down
12 changes: 10 additions & 2 deletions src/mock/index.ts
Expand Up @@ -19,7 +19,6 @@ import {
isEnumType,
isAbstractType,
} from 'graphql';
import { v4 as uuid } from 'uuid';

import { buildSchemaFromTypeDefinitions } from '../generate/index';
import { forEachField } from '../utils/index';
Expand Down Expand Up @@ -54,12 +53,21 @@ function mockServer(
return { query: (query, vars) => graphql(mySchema, query, {}, {}, vars) };
}

function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
// eslint-disable-next-line eqeqeq
const v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}

const defaultMockMap: Map<string, IMockFn> = new Map();
defaultMockMap.set('Int', () => Math.round(Math.random() * 200) - 100);
defaultMockMap.set('Float', () => Math.random() * 200 - 100);
defaultMockMap.set('String', () => 'Hello World');
defaultMockMap.set('Boolean', () => Math.random() > 0.5);
defaultMockMap.set('ID', () => uuid());
defaultMockMap.set('ID', () => uuidv4());

// TODO allow providing a seed such that lengths of list could be deterministic
// this could be done by using casual to get a random list length if the casual
Expand Down
20 changes: 8 additions & 12 deletions src/test/directives.test.ts
@@ -1,4 +1,4 @@
import crypto from 'crypto';
import { createHash } from 'crypto';

import {
ExecutionResult,
Expand Down Expand Up @@ -532,15 +532,15 @@ describe('@directives', () => {

test('can use SchemaDirectiveVisitor as a no-op visitor', () => {
const schema = makeExecutableSchema({ typeDefs });
const methodNamesEncountered = Object.create(null);
const methodNamesEncountered = new Set<string>();

class EnthusiasticVisitor extends SchemaDirectiveVisitor {
public static implementsVisitorMethod(name: string) {
// Pretend this class implements all visitor methods. This is safe
// because the SchemaVisitor base class provides empty stubs for all
// the visitor methods that might be called.
methodNamesEncountered[name] = true;
return methodNamesEncountered[name];
methodNamesEncountered.add(name);
return true;
}
}

Expand All @@ -563,13 +563,9 @@ describe('@directives', () => {
unionDirective: EnthusiasticVisitor,
});

expect(
Object.keys(methodNamesEncountered).sort((a, b) => a.localeCompare(b)),
).toEqual(
Object.keys(SchemaVisitor.prototype)
.filter((name) => name.startsWith('visit'))
.sort((a, b) => a.localeCompare(b)),
);
for (const methodName of methodNamesEncountered) {
expect(methodName in SchemaVisitor.prototype).toBeTruthy();
}
});

test('can handle declared arguments', () => {
Expand Down Expand Up @@ -1210,7 +1206,7 @@ describe('@directives', () => {
description: 'Unique ID',
args: [],
resolve(object: any) {
const hash = crypto.createHash('sha1');
const hash = createHash('sha1');
hash.update(type.name);
from.forEach((fieldName: string) => {
hash.update(String(object[fieldName]));
Expand Down

0 comments on commit 2ffad6d

Please sign in to comment.