graphql-custom-types icon indicating copy to clipboard operation
graphql-custom-types copied to clipboard

Is possible to use custom types outside of javascript?

Open dortamiguel opened this issue 7 years ago • 3 comments

I would like to use this types inside my .graphql files. Is this possible?

dortamiguel avatar Oct 03 '18 16:10 dortamiguel

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?

stylesuxx avatar Oct 03 '18 17:10 stylesuxx

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?

dortamiguel avatar Oct 04 '18 09:10 dortamiguel

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

dortamiguel avatar Oct 04 '18 09:10 dortamiguel