@cdmbase/graphql-type-uri

2.0.0 • Public • Published

graphql-type-uri

URI scalar types for GraphQL.js.

Usage

This package exports a URI value scalar GraphQL.js type:

import graphQLURI from '@cdmbase/graphql-type-uri';

These types can also be imported as follows using CommonJS:

const { graphQLURI } = require('@cdmbase/graphql-type-uri');

Programmatically-constructed schemas

You can use this in a programmatically-constructed schema as with any other scalar type:

import graphQLURI from '@cdmbase/graphql-type-uri';

const GraphQLURI = graphQLURI('URI');
export default new GraphQLObjectType({
  name: 'MyType',

  fields: {
    myValue: { type: GraphQLURI },
  },
});

SDL with GraphQL-tools

When using the SDL with GraphQL-tools, define GraphQLURI as the resolver for the appropriate scalar type in your schema:

import { makeExecutableSchema } from 'graphql-tools';
import graphQLURI, from '@cdmbase/graphql-type-uri';

const GraphQLURI = graphQLURI('URI');
const typeDefs = `
scalar URI

type MyType {
  myValue: URI
}

# ...
`;

const resolvers = {
  URI: GraphQLURI,
};

export default makeExecutableSchema({ typeDefs, resolvers });

Readme

Keywords

Package Sidebar

Install

npm i @cdmbase/graphql-type-uri

Weekly Downloads

114

Version

2.0.0

License

MIT

Unpacked Size

8.96 kB

Total Files

4

Last publish

Collaborators

  • cdmbase