Skip to content

Commit

Permalink
Merge pull request #246 from IvanGoncharov/pr_branch
Browse files Browse the repository at this point in the history
Update prettier and sync up its config with graphql-js
  • Loading branch information
IvanGoncharov committed Jun 24, 2020
2 parents ecc478e + 5eeb021 commit 997baa5
Show file tree
Hide file tree
Showing 27 changed files with 261 additions and 250 deletions.
8 changes: 4 additions & 4 deletions .babelrc
Expand Up @@ -9,17 +9,17 @@
"transform-es2015-function-name",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
["transform-es2015-classes", {loose: true}],
["transform-es2015-classes", { "loose": true }],
"transform-es2015-object-super",
"transform-es2015-shorthand-properties",
"transform-es2015-duplicate-keys",
"transform-es2015-computed-properties",
"check-es2015-constants",
["transform-es2015-spread", {loose: true}],
["transform-es2015-spread", { "loose": true }],
"transform-es2015-parameters",
["transform-es2015-destructuring", {loose: true}],
["transform-es2015-destructuring", { "loose": true }],
"transform-es2015-block-scoping",
"transform-es2015-modules-commonjs",
"transform-regenerator",
"transform-regenerator"
]
}
34 changes: 17 additions & 17 deletions .eslintrc
@@ -1,10 +1,7 @@
{
"parser": "babel-eslint",

"plugins": [
"babel",
"flowtype"
],
"plugins": ["babel", "flowtype"],

"env": {
"es6": true,
Expand All @@ -16,16 +13,16 @@
"flowtype/space-before-type-colon": [2, "never"],
"flowtype/space-before-generic-bracket": [2, "never"],
"flowtype/union-intersection-spacing": [2, "always"],
"flowtype/no-weak-types": [2, {"any": false}],
"flowtype/no-weak-types": [2, { "any": false }],
"flowtype/define-flow-type": 2,
"flowtype/use-flow-type": 2,
"flowtype/semi": 2,

"arrow-spacing": 2,
"block-scoped-var": 0,
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"callback-return": 2,
"camelcase": [2, {"properties": "always"}],
"camelcase": [2, { "properties": "always" }],
"comma-dangle": 0,
"comma-spacing": 0,
"comma-style": [2, "last"],
Expand All @@ -41,13 +38,13 @@
"eqeqeq": 2,
"func-names": 0,
"func-style": 0,
"generator-star-spacing": [2, {"before": true, "after": false}],
"generator-star-spacing": [2, { "before": true, "after": false }],
"guard-for-in": 2,
"handle-callback-err": [2, "error"],
"id-length": 0,
"id-match": [2, "^(?:_?[a-zA-Z0-9]*)|[_A-Z0-9]+$"],
"init-declarations": 0,
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": 2,
"linebreak-style": 2,
"lines-around-comment": 0,
Expand Down Expand Up @@ -101,7 +98,7 @@
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": [2, {"allowLoop": true}],
"no-labels": [2, { "allowLoop": true }],
"no-lone-blocks": 2,
"no-lonely-if": 2,
"no-loop-func": 0,
Expand Down Expand Up @@ -151,7 +148,7 @@
"no-unneeded-ternary": 2,
"no-unreachable": 2,
"no-unused-expressions": 2,
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
"no-unused-vars": [2, { "vars": "all", "args": "after-used" }],
"no-use-before-define": 0,
"no-useless-call": 2,
"no-useless-escape": 2,
Expand All @@ -168,17 +165,20 @@
"prefer-const": 2,
"prefer-reflect": 0,
"prefer-spread": 0,
"quote-props": [2, "as-needed", {"numbers": true}],
"quote-props": [2, "as-needed", { "numbers": true }],
"radix": 2,
"require-yield": 2,
"semi": [2, "always"],
"semi-spacing": [2, {"before": false, "after": true}],
"semi-spacing": [2, { "before": false, "after": true }],
"sort-vars": 0,
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
"space-before-function-paren": [
2,
{ "anonymous": "always", "named": "never" }
],
"space-in-parens": 0,
"space-infix-ops": [2, {"int32Hint": false}],
"space-unary-ops": [2, {"words": true, "nonwords": false}],
"space-infix-ops": [2, { "int32Hint": false }],
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [2, "always"],
"strict": 0,
"use-isnan": 2,
Expand All @@ -187,6 +187,6 @@
"vars-on-top": 0,
"wrap-iife": 2,
"wrap-regex": 0,
"yoda": [2, "never", {"exceptRange": true}]
"yoda": [2, "never", { "exceptRange": true }]
}
}
4 changes: 1 addition & 3 deletions .prettierrc
@@ -1,6 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": false,
"jsxBracketSameLine": true
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -16,7 +16,7 @@ before_install:
- npm config set spin false --global

script:
- if [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then npm run lint && npm run check && npm run cover:lcov; else npm run testonly; fi
- if [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then npm run prettier:check && npm run lint && npm run check && npm run cover:lcov; else npm run testonly; fi

after_success:
- if [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js; fi
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
@@ -1,5 +1,4 @@
Contributing
============
# Contributing

After cloning this repo, ensure dependencies are installed by running:

Expand Down
62 changes: 32 additions & 30 deletions README.md
Expand Up @@ -42,19 +42,21 @@ Helper functions are provided for both building the GraphQL types for connection
An example usage of these methods from the [test schema](src/__tests__/starWarsSchema.js):

```js
var {connectionType: ShipConnection} =
connectionDefinitions({nodeType: shipType});
var { connectionType: ShipConnection } = connectionDefinitions({
nodeType: shipType,
});
var factionType = new GraphQLObjectType({
name: 'Faction',
fields: () => ({
ships: {
type: ShipConnection,
args: connectionArgs,
resolve: (faction, args) => connectionFromArray(
faction.ships.map((id) => data.Ship[id]),
args
),
}
resolve: (faction, args) =>
connectionFromArray(
faction.ships.map((id) => data.Ship[id]),
args,
),
},
}),
});
```
Expand All @@ -65,38 +67,38 @@ This shows adding a `ships` field to the `Faction` object that is a connection.

Helper functions are provided for both building the GraphQL types for nodes and for implementing global IDs around local IDs.

- `nodeDefinitions` returns the `Node` interface that objects can implement, and returns the `node` root field to include on the query type. To implement this, it takes a function to resolve an ID to an object, and to determine the type of a given object.
- `toGlobalId` takes a type name and an ID specific to that type name, and returns a "global ID" that is unique among all types.
- `fromGlobalId` takes the "global ID" created by `toGlobalID`, and returns the type name and ID used to create it.
- `globalIdField` creates the configuration for an `id` field on a node.
- `pluralIdentifyingRootField` creates a field that accepts a list of non-ID identifiers (like a username) and maps them to their corresponding objects.
- `nodeDefinitions` returns the `Node` interface that objects can implement, and returns the `node` root field to include on the query type. To implement this, it takes a function to resolve an ID to an object, and to determine the type of a given object.
- `toGlobalId` takes a type name and an ID specific to that type name, and returns a "global ID" that is unique among all types.
- `fromGlobalId` takes the "global ID" created by `toGlobalID`, and returns the type name and ID used to create it.
- `globalIdField` creates the configuration for an `id` field on a node.
- `pluralIdentifyingRootField` creates a field that accepts a list of non-ID identifiers (like a username) and maps them to their corresponding objects.

An example usage of these methods from the [test schema](src/__tests__/starWarsSchema.js):

```js
var {nodeInterface, nodeField} = nodeDefinitions(
var { nodeInterface, nodeField } = nodeDefinitions(
(globalId) => {
var {type, id} = fromGlobalId(globalId);
var { type, id } = fromGlobalId(globalId);
return data[type][id];
},
(obj) => {
return obj.ships ? factionType : shipType;
}
},
);

var factionType = new GraphQLObjectType({
name: 'Faction',
fields: () => ({
id: globalIdField(),
}),
interfaces: [nodeInterface]
interfaces: [nodeInterface],
});

var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField
})
node: nodeField,
}),
});
```

Expand All @@ -106,7 +108,7 @@ This uses `nodeDefinitions` to construct the `Node` interface and the `node` fie

A helper function is provided for building mutations with single inputs and client mutation IDs.

- `mutationWithClientMutationId` takes a name, input fields, output fields, and a mutation method to map from the input fields to the output fields, performing the mutation along the way. It then creates and returns a field configuration that can be used as a top-level field on the mutation type.
- `mutationWithClientMutationId` takes a name, input fields, output fields, and a mutation method to map from the input fields to the output fields, performing the mutation along the way. It then creates and returns a field configuration that can be used as a top-level field on the mutation type.

An example usage of these methods from the [test schema](src/__tests__/starWarsSchema.js):

Expand All @@ -115,41 +117,41 @@ var shipMutation = mutationWithClientMutationId({
name: 'IntroduceShip',
inputFields: {
shipName: {
type: new GraphQLNonNull(GraphQLString)
type: new GraphQLNonNull(GraphQLString),
},
factionId: {
type: new GraphQLNonNull(GraphQLID)
}
type: new GraphQLNonNull(GraphQLID),
},
},
outputFields: {
ship: {
type: shipType,
resolve: (payload) => data['Ship'][payload.shipId]
resolve: (payload) => data['Ship'][payload.shipId],
},
faction: {
type: factionType,
resolve: (payload) => data['Faction'][payload.factionId]
}
resolve: (payload) => data['Faction'][payload.factionId],
},
},
mutateAndGetPayload: ({shipName, factionId}) => {
mutateAndGetPayload: ({ shipName, factionId }) => {
var newShip = {
id: getNewShipId(),
name: shipName
name: shipName,
};
data.Ship[newShip.id] = newShip;
data.Faction[factionId].ships.push(newShip.id);
return {
shipId: newShip.id,
factionId: factionId,
};
}
},
});

var mutationType = new GraphQLObjectType({
name: 'Mutation',
fields: () => ({
introduceShip: shipMutation
})
introduceShip: shipMutation,
}),
});
```

Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -28,8 +28,9 @@
},
"scripts": {
"prepublish": "./resources/prepublish.sh",
"prettier": "find src -name '*.js' | xargs prettier --write",
"test": "npm run lint && npm run check && npm run testonly",
"prettier": "prettier --write --list-different .",
"prettier:check": "prettier --check .",
"test": "npm run lint && npm run check && npm run testonly && npm run prettier:check",
"testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
"lint": "eslint src",
"check": "flow check",
Expand Down Expand Up @@ -76,7 +77,7 @@
"graphql": "^14.1.1",
"isparta": "4.1.0",
"mocha": "^5.2.0",
"prettier": "^1.19.1",
"prettier": "2.0.5",
"sane": "^2.5.2"
}
}

0 comments on commit 997baa5

Please sign in to comment.