@cdmbase/graphql-type-uri
v4.0.0
Published
JSON scalar types for GraphQL.js
Downloads
885
Readme
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 });