Error: Unknown type "Json". Did you mean "JSON"?

Not sure if this is a Redwood error, or a user error, so posting here first, before creating a Github issue

yarn run v1.22.4
$ E:\dev\rw-tut-2\node_modules\.bin\rw info

  System:
    OS: Windows 10 10.0.18362
  Binaries:
    Node: 14.4.0 - ~\AppData\Local\Temp\yarn--1593080477130-0.8390993409917122\node.CMD
    Yarn: 1.22.4 - ~\AppData\Local\Temp\yarn--1593080477130-0.8390993409917122\yarn.CMD
  Browsers:
    Edge: 44.18362.449.0
  npmPackages:
    @redwoodjs/core: ^0.12.0 => 0.12.0

schema.prisma

datasource DS {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider      = "prisma-client-js"
  binaryTargets = env("BINARY_TARGET")
}

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  jsonData  Json
  createdAt DateTime @default(now())
}

Both yarn rw db save and yarn rw db up completes without errors. Then I scaffold the post CRUD, and that finishes without errors too. But when I then try to start the dev server I get this output

$ yarn rw dev
yarn run v1.22.4
$ E:\dev\rw-tut-2\node_modules\.bin\rw dev
$ E:\dev\rw-tut-2\node_modules\.bin\dev-server
$ E:\dev\rw-tut-2\node_modules\.bin\webpack-dev-server --config ../node_modules/@redwoodjs/core/config/webpack.development.js
api | Running at 'http://localhost:8911'
api | Watching files in 'E:\dev\rw-tut-2\api\src\functions'
web | i 「wds」: Project is running at http://localhost:8910/
web | i 「wds」: webpack output is served from /
web | i 「wds」: Content not from webpack is served from E:\dev\rw-tut-2\web
web | i 「wds」: 404s will fallback to /index.html
api |
api | Error: Unknown type "Json". Did you mean "JSON"?
api |
api | Unknown type "Json". Did you mean "JSON"?
api |
api | Unknown type "Json". Did you mean "JSON"?
api |
api | at E:\dev\rw-tut-2\api\src\functions\/graphql.js(anonymous):14
api | 9
api | 10  const schemas = importAll('api', 'graphql')
api | 11  const services = importAll('api', 'services')
api | 12
api | 13  export const handler = createGraphQLHandler({
api | 14    schema: makeMergedSchema({
api | 15      schemas,
api | 16      services: makeServices({ services }),
api | 17    }),
api | 18    db,
api | 19  })
api |
api | 1 assertValidSDL
api |   E:\dev\rw-tut-2\node_modules\graphql\validation\validate.js:108
api |
api | 2 Object.buildASTSchema
api |   E:\dev\rw-tut-2\node_modules\graphql\utilities\buildASTSchema.js:71
api |
api | 3 Object.buildSchemaFromTypeDefinitions
api |   E:\dev\rw-tut-2\node_modules\graphql-tools\src\generate\buildSchemaFromTypeDefinitions.ts:45
api |
api | 4 makeExecutableSchema
api |   E:\dev\rw-tut-2\node_modules\graphql-tools\src\makeExecutableSchema.ts:52
api |
api | 5 makeMergedSchema
api |   E:\dev\rw-tut-2\node_modules\@redwoodjs\api\src\makeMergedSchema\makeMergedSchema.ts:155
api |
api | 6 Module._compile
api |   E:\dev\rw-tut-2\node_modules\pirates\lib\index.js:99
api |
api | 7 Object.newLoader [as .js]
api |   E:\dev\rw-tut-2\node_modules\pirates\lib\index.js:104
api |

Trying to go to http://localhost:8910/posts I get “Something went wrong” and my browser console has this:

12:25:29.388 log.js:24 [HMR] Waiting for update signal from WDS...
12:25:29.593 .netlify/functions/graphql:1 Failed to load resource: the server responded with a status of 404 (Not Found)
12:25:29.595 invariant.esm.js:29 [Network error]: ServerParseError: Unexpected token F in JSON at position 0
(anonymous) @ invariant.esm.js:29
12:25:29.599 index.js:1 Error: Network error: Unexpected token F in JSON at position 0
    at new ApolloError (bundle.esm.js:63)
    at ObservableQuery.push.../node_modules/apollo-client/bundle.esm.js.ObservableQuery.getCurrentResult (bundle.esm.js:159)
    at QueryData.push.../node_modules/@apollo/react-hooks/lib/react-hooks.esm.js.QueryData.getQueryResult (react-hooks.esm.js:258)
    at QueryData._this.getExecuteResult (react-hooks.esm.js:73)

So, am I doing something wrong, or is Redwood doing something wrong? :slight_smile:

If I remove jsonData Json from the schema everything works as it should

Interesting… Do you have a posts.sdl.js file?

import gql from 'graphql-tag'

export const schema = gql`
  type Post {
    id: Int!
    title: String!
    jsonData: Json!
    createdAt: DateTime!
  }

  type Query {
    posts: [Post!]!
    post(id: Int!): Post!
  }

  input CreatePostInput {
    title: String!
    jsonData: Json!
  }

  input UpdatePostInput {
    title: String
    jsonData: Json
  }

  type Mutation {
    createPost(input: CreatePostInput!): Post!
    updatePost(id: Int!, input: UpdatePostInput!): Post!
    deletePost(id: Int!): Post!
  }
`

Err, packages/api/src/makeMergedSchema/rootSchema.ts: JSON: GraphQLJSON, that doesn’t look right, does it? I’ll dig in to that file and see if I can see something

I have no idea what I’m doing, but this seems to work so far…

in rootSchema.ts

export const schema = gql`
  scalar Date
  scalar Time
  scalar DateTime
  scalar Json
  scalar JSONObject

  type Redwood {
    version: String
    currentUser: Json
  }

  type Query {
    redwood: Redwood
  }
`

export const resolvers = {
  Date: GraphQLDate,
  Time: GraphQLTime,
  DateTime: GraphQLDateTime,
  Json: {
    ...GraphQLJSON,
    name: 'Json',
  },
  JSONObject: GraphQLJSONObject,
  Query: {
    redwood: () => ({
      version: apiPackageJson.version,
      currentUser: (_args: any, context: Context) => {
        return context?.currentUser
      }
    }),
  },
}
1 Like

Just looping in here. Rob and I had a previous conversation about JSON when Prisma support first came out – it was buggy for awhile but I think it’s been resolved on their end: JSONB support (from Prisma 2.0.0.beta4)

However, this is the first time I know of anyone trying it with the RW Generators. You’re a trailblazer, Tobbe! :laughing: