From e94c2fa42992bd58f92709189c1ccc4b203d11b5 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sat, 15 May 2021 19:09:40 +0300 Subject: [PATCH] Update prettier to 2.3 (#3094) --- benchmark/benchmark.js | 3 ++- integrationTests/ts/index.ts | 2 +- package-lock.json | 14 ++++++------ package.json | 2 +- resources/gen-changelog.js | 7 +++--- src/error/formatError.d.ts | 2 +- src/execution/execute.d.ts | 4 ++-- src/execution/execute.js | 22 +++++++++---------- src/jsutils/memoize3.d.ts | 2 +- src/language/directiveLocation.d.ts | 3 ++- src/type/definition.d.ts | 8 +++---- src/type/definition.js | 3 ++- src/type/directives.js | 21 ++++++++---------- src/type/introspection.js | 7 +++--- src/type/scalars.js | 11 +++++++--- src/type/schema.js | 4 +--- src/type/validate.js | 5 ++--- .../__tests__/getOperationRootType-test.js | 7 ++---- src/utilities/getIntrospectionQuery.d.ts | 6 ++--- src/utilities/typedQueryDocumentNode.d.ts | 2 +- .../rules/FieldsOnCorrectTypeRule.js | 5 ++--- src/validation/specifiedRules.js | 7 +++--- 22 files changed, 71 insertions(+), 76 deletions(-) diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index 55125a83fa..fc966f655b 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -117,7 +117,8 @@ async function collectSamples(modulePath) { // T-Distribution two-tailed critical values for 95% confidence. // See http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm. -const tTable = /* prettier-ignore */ { +// prettier-ignore +const tTable = { '1': 12.706, '2': 4.303, '3': 3.182, '4': 2.776, '5': 2.571, '6': 2.447, '7': 2.365, '8': 2.306, '9': 2.262, '10': 2.228, '11': 2.201, '12': 2.179, '13': 2.16, '14': 2.145, '15': 2.131, '16': 2.12, '17': 2.11, '18': 2.101, diff --git a/integrationTests/ts/index.ts b/integrationTests/ts/index.ts index 46a5c50c62..41bbba2e43 100644 --- a/integrationTests/ts/index.ts +++ b/integrationTests/ts/index.ts @@ -21,7 +21,7 @@ declare module 'graphql' { interface GraphQLFieldExtensions< _TSource, _TContext, - _TArgs = { [argName: string]: any } + _TArgs = { [argName: string]: any }, > { someFieldExtension?: SomeExtension; } diff --git a/package-lock.json b/package-lock.json index 9e2684297a..7ebfaffaa9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "flow-bin": "0.150.0", "mocha": "8.3.2", "nyc": "15.1.0", - "prettier": "2.2.1", + "prettier": "2.3.0", "typescript": "4.2.4" }, "engines": { @@ -5701,9 +5701,9 @@ } }, "node_modules/prettier": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", - "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.0.tgz", + "integrity": "sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==", "dev": true, "bin": { "prettier": "bin-prettier.js" @@ -11417,9 +11417,9 @@ "dev": true }, "prettier": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", - "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.0.tgz", + "integrity": "sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==", "dev": true }, "process-on-spawn": { diff --git a/package.json b/package.json index 94e3945421..0438540d26 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "flow-bin": "0.150.0", "mocha": "8.3.2", "nyc": "15.1.0", - "prettier": "2.2.1", + "prettier": "2.3.0", "typescript": "4.2.4" } } diff --git a/resources/gen-changelog.js b/resources/gen-changelog.js index 48a3cf366a..49412a008d 100644 --- a/resources/gen-changelog.js +++ b/resources/gen-changelog.js @@ -47,9 +47,10 @@ if (!packageJSON.repository || typeof packageJSON.repository.url !== 'string') { process.exit(1); } -const repoURLMatch = /https:\/\/github.com\/(?[^/]+)\/(?[^/]+).git/.exec( - packageJSON.repository.url, -); +const repoURLMatch = + /https:\/\/github.com\/(?[^/]+)\/(?[^/]+).git/.exec( + packageJSON.repository.url, + ); if (repoURLMatch == null) { console.error('Cannot extract organization and repo name from repo URL!'); process.exit(1); diff --git a/src/error/formatError.d.ts b/src/error/formatError.d.ts index 1fdea0c355..8877e5f7fd 100644 --- a/src/error/formatError.d.ts +++ b/src/error/formatError.d.ts @@ -12,7 +12,7 @@ export function formatError(error: GraphQLError): GraphQLFormattedError; * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors */ export interface GraphQLFormattedError< - TExtensions extends Record = Record + TExtensions extends Record = Record, > { /** * A short, human-readable summary of the problem that **SHOULD NOT** change diff --git a/src/execution/execute.d.ts b/src/execution/execute.d.ts index 1db6f20b06..adc48e801c 100644 --- a/src/execution/execute.d.ts +++ b/src/execution/execute.d.ts @@ -70,7 +70,7 @@ export interface ExecutionContext { */ export interface ExecutionResult< TData = { [key: string]: any }, - TExtensions = { [key: string]: any } + TExtensions = { [key: string]: any }, > { errors?: ReadonlyArray; // TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229 @@ -80,7 +80,7 @@ export interface ExecutionResult< export interface FormattedExecutionResult< TData = { [key: string]: any }, - TExtensions = { [key: string]: any } + TExtensions = { [key: string]: any }, > { errors?: ReadonlyArray; // TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229 diff --git a/src/execution/execute.js b/src/execution/execute.js index 63e1536f6d..0d7f0f7a12 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -1140,19 +1140,17 @@ export const defaultTypeResolver: GraphQLTypeResolver = function ( * and returns it as the result, or if it's a function, returns the result * of calling that function while passing along args and context value. */ -export const defaultFieldResolver: GraphQLFieldResolver< - mixed, - mixed, -> = function (source: any, args, contextValue, info) { - // ensure source is a value for which property access is acceptable. - if (isObjectLike(source) || typeof source === 'function') { - const property = source[info.fieldName]; - if (typeof property === 'function') { - return source[info.fieldName](args, contextValue, info); +export const defaultFieldResolver: GraphQLFieldResolver = + function (source: any, args, contextValue, info) { + // ensure source is a value for which property access is acceptable. + if (isObjectLike(source) || typeof source === 'function') { + const property = source[info.fieldName]; + if (typeof property === 'function') { + return source[info.fieldName](args, contextValue, info); + } + return property; } - return property; - } -}; + }; /** * This method looks up the field on the given type definition. diff --git a/src/jsutils/memoize3.d.ts b/src/jsutils/memoize3.d.ts index e3752c6311..f4254cd9f9 100644 --- a/src/jsutils/memoize3.d.ts +++ b/src/jsutils/memoize3.d.ts @@ -6,5 +6,5 @@ export function memoize3< A1 extends object, A2 extends object, A3 extends object, - R + R, >(fn: (a1: A1, a2: A2, a3: A3) => R): (a1: A1, a2: A2, a3: A3) => R; diff --git a/src/language/directiveLocation.d.ts b/src/language/directiveLocation.d.ts index b803e40313..7275496405 100644 --- a/src/language/directiveLocation.d.ts +++ b/src/language/directiveLocation.d.ts @@ -29,4 +29,5 @@ export const DirectiveLocation: Readonly<{ /** * The enum type representing the directive location values. */ -export type DirectiveLocationEnum = typeof DirectiveLocation[keyof typeof DirectiveLocation]; +export type DirectiveLocationEnum = + typeof DirectiveLocation[keyof typeof DirectiveLocation]; diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index c520340b0e..50e9dd53f3 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -472,7 +472,7 @@ export type GraphQLIsTypeOfFn = ( export type GraphQLFieldResolver< TSource, TContext, - TArgs = { [argName: string]: any } + TArgs = { [argName: string]: any }, > = ( source: TSource, args: TArgs, @@ -508,7 +508,7 @@ export interface GraphQLResolveInfo { export interface GraphQLFieldExtensions< _TSource, _TContext, - _TArgs = { [argName: string]: any } + _TArgs = { [argName: string]: any }, > { [attributeName: string]: unknown; } @@ -516,7 +516,7 @@ export interface GraphQLFieldExtensions< export interface GraphQLFieldConfig< TSource, TContext, - TArgs = { [argName: string]: any } + TArgs = { [argName: string]: any }, > { description?: Maybe; type: GraphQLOutputType; @@ -561,7 +561,7 @@ export type GraphQLFieldConfigMap = ObjMap< export interface GraphQLField< TSource, TContext, - TArgs = { [key: string]: any } + TArgs = { [key: string]: any }, > { name: string; description: Maybe; diff --git a/src/type/definition.js b/src/type/definition.js index 2aca26f56b..0281beb116 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -1430,7 +1430,8 @@ type GraphQLEnumTypeNormalizedConfig = { extensionASTNodes: $ReadOnlyArray, }; -export type GraphQLEnumValueConfigMap /* */ = ObjMap */>; +export type GraphQLEnumValueConfigMap /* */ = + ObjMap */>; export type GraphQLEnumValueConfig /* */ = { description?: ?string, diff --git a/src/type/directives.js b/src/type/directives.js index ee1f6389d0..2af25d9fc0 100644 --- a/src/type/directives.js +++ b/src/type/directives.js @@ -167,8 +167,8 @@ export const DEFAULT_DEPRECATION_REASON = 'No longer supported'; /** * Used to declare element of a GraphQL schema as deprecated. */ -export const GraphQLDeprecatedDirective: GraphQLDirective = new GraphQLDirective( - { +export const GraphQLDeprecatedDirective: GraphQLDirective = + new GraphQLDirective({ name: 'deprecated', description: 'Marks an element of a GraphQL schema as no longer supported.', locations: [ @@ -185,14 +185,13 @@ export const GraphQLDeprecatedDirective: GraphQLDirective = new GraphQLDirective defaultValue: DEFAULT_DEPRECATION_REASON, }, }, - }, -); + }); /** * Used to provide a URL for specifying the behaviour of custom scalar definitions. */ -export const GraphQLSpecifiedByDirective: GraphQLDirective = new GraphQLDirective( - { +export const GraphQLSpecifiedByDirective: GraphQLDirective = + new GraphQLDirective({ name: 'specifiedBy', description: 'Exposes a URL that specifies the behaviour of this scalar.', locations: [DirectiveLocation.SCALAR], @@ -202,20 +201,18 @@ export const GraphQLSpecifiedByDirective: GraphQLDirective = new GraphQLDirectiv description: 'The URL that specifies the behaviour of this scalar.', }, }, - }, -); + }); /** * The full list of specified directives. */ -export const specifiedDirectives: $ReadOnlyArray = Object.freeze( - [ +export const specifiedDirectives: $ReadOnlyArray = + Object.freeze([ GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDeprecatedDirective, GraphQLSpecifiedByDirective, - ], -); + ]); export function isSpecifiedDirective(directive: GraphQLDirective): boolean { return specifiedDirectives.some(({ name }) => name === directive.name); diff --git a/src/type/introspection.js b/src/type/introspection.js index f0bce5838a..30dae56b9a 100644 --- a/src/type/introspection.js +++ b/src/type/introspection.js @@ -528,8 +528,8 @@ export const TypeNameMetaFieldDef: GraphQLField = { astNode: undefined, }; -export const introspectionTypes: $ReadOnlyArray = Object.freeze( - [ +export const introspectionTypes: $ReadOnlyArray = + Object.freeze([ __Schema, __Directive, __DirectiveLocation, @@ -538,8 +538,7 @@ export const introspectionTypes: $ReadOnlyArray = Object.freez __InputValue, __EnumValue, __TypeKind, - ], -); + ]); export function isIntrospectionType(type: GraphQLNamedType): boolean { return introspectionTypes.some(({ name }) => type.name === name); diff --git a/src/type/scalars.js b/src/type/scalars.js index 0d9bdc955b..1b31b9e01f 100644 --- a/src/type/scalars.js +++ b/src/type/scalars.js @@ -270,9 +270,14 @@ export const GraphQLID: GraphQLScalarType = new GraphQLScalarType({ }, }); -export const specifiedScalarTypes: $ReadOnlyArray = Object.freeze( - [GraphQLString, GraphQLInt, GraphQLFloat, GraphQLBoolean, GraphQLID], -); +export const specifiedScalarTypes: $ReadOnlyArray = + Object.freeze([ + GraphQLString, + GraphQLInt, + GraphQLFloat, + GraphQLBoolean, + GraphQLID, + ]); export function isSpecifiedScalarType(type: GraphQLNamedType): boolean { return specifiedScalarTypes.some(({ name }) => type.name === name); diff --git a/src/type/schema.js b/src/type/schema.js index 9a1fa96cc8..d0bf79787a 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -282,9 +282,7 @@ export class GraphQLSchema { : this.getImplementations(abstractType).objects; } - getImplementations( - interfaceType: GraphQLInterfaceType, - ): { + getImplementations(interfaceType: GraphQLInterfaceType): { objects: /* $ReadOnly */ Array, interfaces: /* $ReadOnly */ Array, } { diff --git a/src/type/validate.js b/src/type/validate.js index 919e58248d..fff65f90d5 100644 --- a/src/type/validate.js +++ b/src/type/validate.js @@ -202,9 +202,8 @@ function validateName( } function validateTypes(context: SchemaValidationContext): void { - const validateInputObjectCircularRefs = createInputObjectCircularRefsValidator( - context, - ); + const validateInputObjectCircularRefs = + createInputObjectCircularRefsValidator(context); const typeMap = context.schema.getTypeMap(); for (const type of Object.values(typeMap)) { // Ensure all provided types are in fact GraphQL type. diff --git a/src/utilities/__tests__/getOperationRootType-test.js b/src/utilities/__tests__/getOperationRootType-test.js index d96864fea6..8bc87d7d2f 100644 --- a/src/utilities/__tests__/getOperationRootType-test.js +++ b/src/utilities/__tests__/getOperationRootType-test.js @@ -77,11 +77,8 @@ describe('getOperationRootType', () => { const schemaNode = doc.definitions[0]; invariant(schemaNode.kind === Kind.SCHEMA_DEFINITION); - const [ - queryNode, - mutationNode, - subscriptionNode, - ] = schemaNode.operationTypes; + const [queryNode, mutationNode, subscriptionNode] = + schemaNode.operationTypes; expect(getOperationRootType(testSchema, queryNode)).to.equal(queryType); expect(getOperationRootType(testSchema, mutationNode)).to.equal( diff --git a/src/utilities/getIntrospectionQuery.d.ts b/src/utilities/getIntrospectionQuery.d.ts index b34425b456..ce805aa348 100644 --- a/src/utilities/getIntrospectionQuery.d.ts +++ b/src/utilities/getIntrospectionQuery.d.ts @@ -117,14 +117,14 @@ export interface IntrospectionInputObjectType { } export interface IntrospectionListTypeRef< - T extends IntrospectionTypeRef = IntrospectionTypeRef + T extends IntrospectionTypeRef = IntrospectionTypeRef, > { readonly kind: 'LIST'; readonly ofType: T; } export interface IntrospectionNonNullTypeRef< - T extends IntrospectionTypeRef = IntrospectionTypeRef + T extends IntrospectionTypeRef = IntrospectionTypeRef, > { readonly kind: 'NON_NULL'; readonly ofType: T; @@ -154,7 +154,7 @@ export type IntrospectionInputTypeRef = >; export interface IntrospectionNamedTypeRef< - T extends IntrospectionType = IntrospectionType + T extends IntrospectionType = IntrospectionType, > { readonly kind: T['kind']; readonly name: string; diff --git a/src/utilities/typedQueryDocumentNode.d.ts b/src/utilities/typedQueryDocumentNode.d.ts index 0d7b8de17d..82d74f1473 100644 --- a/src/utilities/typedQueryDocumentNode.d.ts +++ b/src/utilities/typedQueryDocumentNode.d.ts @@ -5,7 +5,7 @@ import { DocumentNode, ExecutableDefinitionNode } from '../language/ast'; */ export interface TypedQueryDocumentNode< TResponseData = Record, - TRequestVariables = Record + TRequestVariables = Record, > extends DocumentNode { readonly definitions: ReadonlyArray; // FIXME: remove once TS implements proper way to enforce nominal typing diff --git a/src/validation/rules/FieldsOnCorrectTypeRule.js b/src/validation/rules/FieldsOnCorrectTypeRule.js index d2a37bb75e..1b2e066042 100644 --- a/src/validation/rules/FieldsOnCorrectTypeRule.js +++ b/src/validation/rules/FieldsOnCorrectTypeRule.js @@ -80,9 +80,8 @@ function getSuggestedTypeNames( return []; } - const suggestedTypes: Set< - GraphQLObjectType | GraphQLInterfaceType, - > = new Set(); + const suggestedTypes: Set = + new Set(); const usageCount = Object.create(null); for (const possibleType of schema.getPossibleTypes(type)) { if (!possibleType.getFields()[fieldName]) { diff --git a/src/validation/specifiedRules.js b/src/validation/specifiedRules.js index 5f622d27ca..1440f5b37a 100644 --- a/src/validation/specifiedRules.js +++ b/src/validation/specifiedRules.js @@ -131,8 +131,8 @@ export const specifiedRules: $ReadOnlyArray = Object.freeze([ /** * @internal */ -export const specifiedSDLRules: $ReadOnlyArray = Object.freeze( - [ +export const specifiedSDLRules: $ReadOnlyArray = + Object.freeze([ LoneSchemaDefinitionRule, UniqueOperationTypesRule, UniqueTypeNamesRule, @@ -147,5 +147,4 @@ export const specifiedSDLRules: $ReadOnlyArray = Object.freez UniqueArgumentNamesRule, UniqueInputFieldNamesRule, ProvidedRequiredArgumentsOnDirectivesRule, - ], -); + ]);