Skip to content

Commit

Permalink
Merge pull request #26 from okgrow/v0.4.3
Browse files Browse the repository at this point in the history
V0.4.3
  • Loading branch information
ccuilla authored Jan 19, 2019
2 parents a28cecb + 3f8efcb commit 461bb83
Show file tree
Hide file tree
Showing 21 changed files with 8,697 additions and 3,635 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
extends: 'airbnb',
rules: {
"linebreak-style": 'off', // Airbnb specifies Unix style line endings, turn this off for Windows users
'implicit-arrow-linebreak': 'off',
'linebreak-style': 'off', // Airbnb specifies Unix style line endings, turn this off for Windows users
'function-paren-newline': 'off',
'import/extensions': ['off', 'never'], // https://github.com/benmosher/eslint-plugin-import/issues/593
'import/named': 'error', // Ensure named imports correspond to a named export in the remote file
Expand All @@ -10,5 +11,6 @@ module.exports = {
'no-mixed-operators': 'off', // Allow && || usage. e.g: const foo = a && a.foo || undefined;
'no-param-reassign': ['error', { props: false }], // Allows assignment of new properties
'no-underscore-dangle': 'off', // Mongo _id
'operator-linebreak': 'off',
},
};
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.4.2] - 2018-09-??
## [0.4.3] - 2019-01-18

### Changed

- Updated packages and dependencies
- Updated Airbnb eslint rules but disabled a couple and fixed issues for one rule
- Add yarn.lock

### Added

- A new options argument for the RegularExpression scalar

## [0.4.2] - 2018-09-21

### Changed

Expand Down
81 changes: 50 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ scalar URL

In your resolver map, first import them:

```js
```javascript
import {
DateTime,
NonPositiveInt,
Expand All @@ -81,7 +81,7 @@ import {

Then make sure they're in the root resolver map like this:

```js
```javascript
const myResolverMap = {
DateTime,

Expand Down Expand Up @@ -116,13 +116,13 @@ and `UnsignedInt`, respectively.

Alternatively, use the default import and ES6's spread operator syntax:

```js
```javascript
import OKGGraphQLScalars from '@okgrow/graphql-scalars';
```

Then make sure they're in the root resolver map like this:

```js
```javascript
const myResolverMap = {
...OKGGraphQLScalars,

Expand Down Expand Up @@ -162,10 +162,12 @@ These scalars can be used just like the base, built-in ones.
### Usage with Apollo Server

```javascript
import { ApolloServer } from "apollo-server"
import { makeExecutableSchema } from "graphql-tools"
import { ApolloServer } from 'apollo-server';
import { makeExecutableSchema } from 'graphql-tools';
// import all scalars and resolvers
import OKGGraphQLScalars, { OKGScalarDefinitions } from "@okgrow/graphql-scalars"
import OKGGraphQLScalars, {
OKGScalarDefinitions,
} from '@okgrow/graphql-scalars';
// Alternatively, import individual scalars and resolvers
// import { DateTime, DateTimeScalar, ... } from "@okgrow/graphql-scalars"

Expand All @@ -184,9 +186,9 @@ const server = new ApolloServer({
// DateTime,
// ...
// ... remainder of resolver map ...
}
})
})
},
}),
});

server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
Expand All @@ -200,7 +202,7 @@ instance of a new `GraphQLScalarType` object that implements three general funct
`serialize`, `parseValue` and `parseLiteral` which are used at different stages of processing your
GraphQL types during queries and mutations. So creating a new scalar looks like this:

```
```javascript
const MyScalar = new GraphQLScalarType({
'MyScalar',

Expand Down Expand Up @@ -231,33 +233,50 @@ parameters. That's the approach we take here.
Therefore the `RegularExpression` scalar type is really a `GraphQLScalarType` object _generator_
that takes two arguments:

* a name
* the regex you want it to use
- a name
- the regex you want it to use

So to create a new scalar for a given regex, you will do this:

```
```javascript
const MyRegexType = new RegularExpression('MyRegexType', /^ABC$/);
```

Now `MyRegexType` is your new GraphQL scalar type that will enforce a value of, in this case, "ABC".

Add your new scalar type to your resolver map:

```
```javascript
export default {
MyRegexType,
};
```

And to your schema:

```
```graphql
scalar MyRegexType
```

That's it. Now you can use `MyRegexType` as a type in the rest of your schema.

#### RegularExpression options

There is an optional third `options` argument to the RegularExpression constructor that can be used like this:

```javascript
const options = {
errorMessage: (regex, value) => {
if (process.env.NODE_ENV === 'production')
return `Value is invalid format: ${value} `;
else
return `Value does not match the regular expression ${regex}: ${value}`;
},
};

const MyRegexType = new RegularExpression('MyRegexType', /^ABC$/, options);
```

## Why?

The primary purposes these scalars, really of _all_ types are to:
Expand Down Expand Up @@ -342,19 +361,19 @@ and [here](https://stackoverflow.com/questions/578406/what-is-the-ultimate-posta

Which gives us the following countries:

* US - United States
* UK - United Kingdom
* DE - Germany
* CA - Canada
* FR - France
* IT - Italy
* AU - Australia
* NL - Netherlands
* ES - Spain
* DK - Denmark
* SE - Sweden
* BE - Belgium
* IN - India
- US - United States
- UK - United Kingdom
- DE - Germany
- CA - Canada
- FR - France
- IT - Italy
- AU - Australia
- NL - Netherlands
- ES - Spain
- DK - Denmark
- SE - Sweden
- BE - Belgium
- IN - India

This is really a practical decision of weight (of the package) vs. completeness.

Expand All @@ -364,8 +383,8 @@ In the future we might expand this list and use the more comprehensive list foun

A `GraphQLScalarType` object generator that takes two arguments:

* `name` - The name of your custom type
* `regex` - The regex to be used to check against any values for fields with this new type
- `name` - The name of your custom type
- `regex` - The regex to be used to check against any values for fields with this new type

```
const MyRegexType = new RegularExpression('MyRegexType', /^ABC$/);
Expand Down
Loading

0 comments on commit 461bb83

Please sign in to comment.