graphql-custom-types
graphql-custom-types copied to clipboard
Is possible to use custom types outside of javascript?
I would like to use this types inside my .graphql files. Is this possible?
Not sure if I understand the question. This module is intended to be used in schema files, so I would say yes.
But maybe you can tell me your specific use case?
So I tried to do this on my schema.graphql file
# import GraphQLEmail from 'graphql-custom-types'
type User {
id: ID!
email: GraphQLEmail!
}
But I get the following error
/Users/miguel/src/prisma-apollo-example/node_modules/graphql/error/syntaxError.js:24
return new _GraphQLError.GraphQLError("Syntax Error: ".concat(description), undefined, source, [position]);
^
Syntax Error: Unexpected Name "graphql"
GraphQL request (1:1)
1: graphql-custom-types
^
at syntaxError (/Users/miguel/src/prisma-apollo-example/node_modules/graphql/error/syntaxError.js:24:10)
at unexpected (/Users/miguel/src/prisma-apollo-example/node_modules/graphql/language/parser.js:1490:33)
at parseDefinition (/Users/miguel/src/prisma-apollo-example/node_modules/graphql/language/parser.js:153:9)
at many (/Users/miguel/src/prisma-apollo-example/node_modules/graphql/language/parser.js:1520:16)
at parseDocument (/Users/miguel/src/prisma-apollo-example/node_modules/graphql/language/parser.js:113:18)
at Object.parse (/Users/miguel/src/prisma-apollo-example/node_modules/graphql/language/parser.js:48:10)
at getDocumentFromSDL (/Users/miguel/src/prisma-apollo-example/node_modules/graphql-import/src/index.ts:151:12)
at collectDefinitions (/Users/miguel/src/prisma-apollo-example/node_modules/graphql-import/src/index.ts:221:20)
at /Users/miguel/src/prisma-apollo-example/node_modules/graphql-import/src/index.ts:248:7
at Array.forEach (<anonymous>)
Is this how Im supposed to import the custom types?
I'm using apollo server, and this is how I pass the schema to the server.
import { ApolloServer, gql } from "apollo-server";
import { importSchema } from "graphql-import";
import resolvers from "@root/resolvers";
const schema = importSchema("./src/schema.graphql");
const server = new ApolloServer({
typeDefs: gql(schema),
resolvers,
});