Skip to content

Commit

Permalink
Merge 5f1a498 into 49827c0
Browse files Browse the repository at this point in the history
  • Loading branch information
codingmatty committed Mar 16, 2019
2 parents 49827c0 + 5f1a498 commit c448322
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,57 @@ export const GraphQLName = GraphQLScalarTypes.string('Name').min(0).max(36).crea
export const GraphQLAge = GraphQLScalarTypes.number('Age').min(0).max(120).create();
```

### Using Apollo-Server

Here is a minimal example using Apollo Server:

```js
const { ApolloServer, gql } = require('apollo-server');
const { default: GraphQLScalarTypes } = require('graphql-scalar-types');

const schemaString = gql`
# Make sure to define the scalars in the schema string
scalar Name
scalar Email
type Person {
name: Name
email: Email
}
type Query {
successfulPerson: Person
unsuccessfulPerson: Person
}
`;

const resolverFunctions = {
// Now define the resolvers using GraphQLScalarTypes
Name: GraphQLScalarTypes.string('Name').min(1).create(),
Email: GraphQLScalarTypes.string('Email').regex(/[\w\d]+@[\w\d]+\.\w+/, { name: 'Email Regex' }).create(),

Query: {
successfulPerson: () => ({
name: 'Foo Bar',
email: 'test@email.com'
}),
unsuccessfulPerson: () => ({
name: '',
email: 'invalid-email'
})
}
};

const server = new ApolloServer({
typeDefs: schemaString,
resolvers: resolverFunctions
});

server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
```

## API

#### constructor
Expand Down

0 comments on commit c448322

Please sign in to comment.