Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is possible to use custom types outside of javascript? #24

Open
dortamiguel opened this issue Oct 3, 2018 · 3 comments
Open

Is possible to use custom types outside of javascript? #24

dortamiguel opened this issue Oct 3, 2018 · 3 comments
Labels

Comments

@dortamiguel
Copy link

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

@stylesuxx
Copy link
Owner

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?

@dortamiguel
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants