2.0.0 • Published 3 years ago

@cdmbase/graphql-type-uri v2.0.0

Weekly downloads
121
License
MIT
Repository
github
Last release
3 years ago

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 });