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

howtograpql - Nodejs + Prisma - Backend - Cannot query field 'signup' on type 'Mutation' #44

Closed
tnedich opened this issue Sep 22, 2018 · 2 comments

Comments

@tnedich
Copy link

tnedich commented Sep 22, 2018

Good day,

I have cloned graphql-js repo, and changed relevant parts because I am using Prisma server localy.
I am using docker-compose. Here are relevan files:

package.json

{
  "name": "hackernews-node",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start": "node src/index.js",
    "dev": "npm-run-all --parallel start playground",
    "playground": "graphql playground",
    "prisma": "prisma",
    "graphql": "graphql"
  },
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "graphql-yoga": "^1.7.0",
    "jsonwebtoken": "^8.2.0",
    "prisma-binding": "^2.0.2"
  },
  "devDependencies": {
    "graphql-cli": "^2.16.4",
    "npm-run-all": "^4.1.2",
    "prisma": "^1.9.0"
  }
}

docker-compose.yml

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.16
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: postgres
            host: postgres
            port: 5432
            user: prisma
            password: prisma
            migrations: true
  postgres:
    image: postgres:10.5
    restart: always
    ports:
    - "5432:5432"
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    volumes:
      - postgres:/var/lib/postgresql/data
volumes:
  postgres:

.graphqlconfig.yml

projects:
  app:
    schemaPath: src/schema.graphql
    extensions:
      endpoints:
        default: http://localhost:4466
  database:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: database/prisma.yml

prisma.yml

endpoint: http://localhost:4466
datamodel: datamodel.graphql
secret: mysecret123
hooks:
  post-deploy:
    - yarn graphql get-schema --project database

.src/index.js

const { GraphQLServer } = require('graphql-yoga')
const { Prisma } = require('prisma-binding')
const Query = require('./resolvers/Query')
const Mutation = require('./resolvers/Mutation')
const AuthPayload = require('./resolvers/AuthPayload')
const Subscription = require('./resolvers/Subscription')
const Feed = require('./resolvers/Feed')

const resolvers = {
  Query,
  Mutation,
  AuthPayload,
  Subscription,
  Feed
}

const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  context: req => ({
    ...req,
    db: new Prisma({
      typeDefs: 'src/generated/prisma.graphql',
      endpoint: 'http://localhost:4466',
      secret: 'mysecret123',
      debug: true,
    }),
  }),
})
server.start(() => console.log(`Server is running on http://localhost:4466`))

When I run yarn dev, server starts, playground opens, everythinf works , but there are no signup, login, post mutations.

Bellow is image of mutations from GraphQL Playground.

screenshot 2018-09-22 12 03 37

When trying to write post mutation I get:

mutation {
  signup(
    name: "Alice"
    email: "alice@graph.cool"
    password: "graphql"
  ) {
    token
    user {
      id
    }
  }
}

Cannot query field 'signup' on type 'Mutation'

@condef5
Copy link

condef5 commented Sep 25, 2018

Hi, happens that you are duplicating port 4466, in these files graphqlconfig.yml and database\prisma.yml
Try changing this line in your file graphqlconfig.yml :

projects:
  app:
    schemaPath: src/schema.graphql
    extensions:
      endpoints:
        default: http://localhost:4466
  database:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: database/prisma.yml

for this:

projects:
  app:
    schemaPath: src/schema.graphql
    extensions:
      endpoints:
        default: http://localhost:4000
  database:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: database/prisma.yml

And then your graphql editor will be available at http://localhost:4000/

@tnedich
Copy link
Author

tnedich commented Sep 25, 2018

Yeah that is it.

@tnedich tnedich closed this as completed Sep 25, 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

2 participants