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

running project with js error #165

Closed
idkjs opened this issue Apr 16, 2018 · 1 comment
Closed

running project with js error #165

idkjs opened this issue Apr 16, 2018 · 1 comment

Comments

@idkjs
Copy link

idkjs commented Apr 16, 2018

I've stripped out the ts and replaced with js but cant get index.js to read them i think.

After running prisma deploy and then yarn dev i'm getting the following error:

[nodemon] starting `node -r dotenv/config src/index.js`
/Users/prisc_000/code/BHYV/airbnb-server/node_modules/graphql-yoga/node_modules/graphql-tools/dist/schemaGenerator.js:311
        Object.keys(resolveFunctions[typeName]).forEach(function (fieldName) {
               ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at /Users/prisc_000/code/BHYV/airbnb-server/node_modules/graphql-yoga/node_modules/graphql-tools/dist/schemaGenerator.js:311:16
    at Array.forEach (<anonymous>)
    at addResolveFunctionsToSchema (/Users/prisc_000/code/BHYV/airbnb-server/node_modules/graphql-yoga/node_modules/graphql-tools/dist/schemaGenerator.js:303:35)
    at _generateSchema (/Users/prisc_000/code/BHYV/airbnb-server/node_modules/graphql-yoga/node_modules/graphql-tools/dist/schemaGenerator.js:90:5)
    at Object.makeExecutableSchema (/Users/prisc_000/code/BHYV/airbnb-server/node_modules/graphql-yoga/node_modules/graphql-tools/dist/schemaGenerator.js:102:20)
    at new GraphQLServer (/Users/prisc_000/code/BHYV/airbnb-server/node_modules/graphql-yoga/dist/src/index.js:89:53)
    at Object.<anonymous> (/Users/prisc_000/code/BHYV/airbnb-server/src/index.js:5:16)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
[nodemon] app crashed - waiting for file changes before starting...

This is index.js. Error is on const server on line 5.

const { GraphQLServer } = require('graphql-yoga')
const { Prisma } = require('./generated/prisma')
const { resolvers, fragmentReplacements } = require('./resolvers')

const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  context: req => ({
    ...req,
    db: new Prisma({
      // typeDefs: 'src/generated/prisma.graphql',
      fragmentReplacements,
      endpoint: process.env.PRISMA_ENDPOINT,
      secret: process.env.PRISMA_SECRET,
      debug: true,
    }),
  }),
})

server.start(({ port }) =>
  console.log(`Server is running on http://localhost:${port}`),
)

Any idea on what is going on here?

graphqlconfig.yml

projects:
  app:
    schemaPath: src/schema.graphql
    includes:
      - 'queries/{booking,queries}.graphql'
    extensions:
      endpoints:
        default: 'http://localhost:4000'
  prisma:
    schemaPath: "src/generated/prisma.graphql"
    includes: ["database/seed.graphql"]
    extensions:
      prisma: database/prisma.yml
      prepare-binding:
        output: src/generated/prisma.js
        generator: prisma-js
@idkjs idkjs changed the title graphql prepare with javascript running project with js error Apr 16, 2018
@idkjs
Copy link
Author

idkjs commented Apr 16, 2018

figured it out. working repo is https://github.com/idkjs/graphql-server-example

Converting from typescript to js

  1. First change all file names to js then remove any typings. vscode will tell you where they are in problems tab.

  2. deps: yarn add babel-cli babel-preset-env babel-plugin-transform-object-rest-spread -D
    To get this to run I had to change the start scripts and add "babel" property to package.json

  "scripts": {
    ...
    "babel-node": "babel-node --presets=env",
    "start": "nodemon -e js,graphql -x babel-node src/index.js",
    "build": "rm -rf dist && graphql prepare",
    ...
  },
  ...
    "babel": {
    "presets": ["env"],
    "plugins": ["transform-object-rest-spread"]
  },
  1. Set up dotenv for es6 by adding src/env.js then calling it from src/index.js. solution in this issue
    See src/env.js and src/index.js
  2. Change graphqlconfig.yml prepare-bindings to:
prepare-binding:
        output: src/generated/prisma.js
        generator: prisma-js

@idkjs idkjs closed this as completed Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant