nicolasdao / graphql-s2s

Add GraphQL Schema support for type inheritance, generic typing, metadata decoration. Transpile the enriched GraphQL string schema into the standard string schema understood by graphql.js and the Apollo server client.
Other
187 stars 15 forks source link

Using graphql-iso-date and custom scalars #38

Open vonazt opened 4 years ago

vonazt commented 4 years ago

I've been trying to use the graphql-iso-date package with graphql-s2s for DateTime formatting on types and get this error: TypeError: Cannot read property 'directive' of null

Is this a known issue, or is there a workaround? My typeDefs file looks like this:

export const commonTypeDefs = `
scalar DateTime

type Timestamps {
  created: DateTime
  started: DateTime
  modified: DateTime
  completed: DateTime
}`

resolvers:

import { GraphQLDateTime } from "graphql-iso-date"

export const resolvers = {
  DateTime: GraphQLDateTime,
  Query: {
   ...
    }

and my index merging:

import { makeExecutableSchema } from 'graphql-tools'
import commonTypeDefs from './commonTypeDefs'
const { transpileSchema } = require('graphql-s2s').graphqls2s

import typeDefs from './typeDefs.gql'
import { resolvers } from './resolvers'

export const workSchema = makeExecutableSchema({
  typeDefs: [transpileSchema(commonTypeDefs), typeDefs],
  resolvers
})
vonazt commented 4 years ago

seems to have been fixed by changing the export type in commonTypeDefs:

export default `
scalar DateTime

type Timestamps {
  created: DateTime
  started: DateTime
  modified: DateTime
  completed: DateTime
}`