Skip to content

Commit fc70f31

Browse files
cedric25ardatan
authored andcommitted
Readme - Add example for apollo-server-express and CommonJS imports (#192)
* Fix missing comma * Add 'apollo-server-express and CommonJS imports' example * Fix for better 'yourTypeDefs' / 'yourResolvers'
1 parent 78192a5 commit fc70f31

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const myResolverMap = {
170170

171171
USCurrency: USCurrencyResolver,
172172
JSON: JSONResolver,
173-
JSONObject: JSONObjectResolver
173+
JSONObject: JSONObjectResolver,
174174

175175
Query: {
176176
// more stuff here
@@ -299,6 +299,29 @@ const server = new ApolloServer({
299299
});
300300
```
301301

302+
### Usage with apollo-server-express and CommonJS imports
303+
304+
```javascript
305+
const { ApolloServer } = require('apollo-server-express');
306+
// Import individual scalars and resolvers
307+
const { DateTimeResolver, DateTimeTypeDefinition } = require('graphql-scalars');
308+
309+
const server = new ApolloServer({
310+
typeDefs: [
311+
DateTimeTypeDefinition,
312+
...yourTypeDefs,
313+
],
314+
resolvers: [
315+
{ DateTime: DateTimeResolver }, // <-- Notable difference here
316+
...yourResolvers,
317+
],
318+
});
319+
320+
server.listen().then(({ url }) => {
321+
console.log(`🚀 Server ready at ${url}`);
322+
});
323+
```
324+
302325

303326
### Using the RegularExpression scalar
304327

0 commit comments

Comments
 (0)