apollo-server-mongo-id-scalar

1.1.0 • Public • Published

apollo-server-mongo-id-scalar

Mongo ID Custom Scalar for GraphQL and Apollo Server

If we use Mongo with GraphQL and Apollo Server, the mongo response includes _id of the collection as a value.

If we use default ID Scalar, we get an error, because GraphQL does not understand the value, we need to change the value to String.

This small package do that for us. It comes with a Custom Scalar for parsing value to string directly as Scalar and we can re-use in our GraphQL Schemas.

Install

npm install --save apollo-server-mongo-id-scalar

Usage

Create a file where you have located your Schemas files with the following code:

export default `
  scalar MONGOID
`;

In Resolvers folder, save a file with this content:

import mongoId from 'apollo-server-mongo-id-scalar';
 
export default {
  MONGOID: mongoId
}

Now we can use the new Custom Scalar in our Schemas.

export default `
  type User {
    _id: MONGOID
    name: String
  }
`;

Package Sidebar

Install

npm i apollo-server-mongo-id-scalar

Weekly Downloads

3

Version

1.1.0

License

MIT

Unpacked Size

5.51 kB

Total Files

10

Last publish

Collaborators

  • amarquez