GithubHelp home page GithubHelp logo

Comments (7)

leventefrks avatar leventefrks commented on August 24, 2024 1

Yes, there are slight differences between the code in the video and the repo. I spent some time to figure it out but I finally managed to solve it by modifying the db.js file and putting an _ before the word Query in the server.js

db.js:

export const connect = (url = options.dbUrl, opts = {}) => {
return mongoose
.connect(url, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
})
.then(() => console.log('Database Connected'))
.catch(err => console.log(err))
}

server.js:

export const start = async () => {
const rootSchema = `
type Cat {
name: String
}

type _Query {
  myCat: Cat
}

schema {
  query: _Query
  mutation: Mutation
}

`
const schemaTypes = await Promise.all(types.map(loadTypeSchema))

const server = new ApolloServer({
typeDefs: [rootSchema, ...schemaTypes],
resolvers: merge(
{
_Query: {
myCat() {
return { name: 'Garfield' }
}
}
},
product,
coupon,
user
),
async context({ req }) {
const user = await authenticate(req)
return { user }
}
})

from intro-to-graphql.

LeeMellon avatar LeeMellon commented on August 24, 2024

src/server.js

import { ApolloServer } from 'apollo-server'
import { loadTypeSchema } from './utils/schema'
import { authenticate } from './utils/auth'
import { merge } from 'lodash'
import config from './config'
import { connect } from './db'
import product from './types/product/product.resolvers'
import coupon from './types/coupon/coupon.resolvers'
import user from './types/user/user.resolvers'

const types = ['product', 'coupon', 'user']

export const start = async () => {
  const rootSchema = 
    type Cat {
    name: String
    age: Int
    }
    
    type Query {
      myCat: Cat
    }
    
    schema {
      query: Query
      mutation: Mutation
    }
  
  const schemaTypes = await Promise.all(types.map(loadTypeSchema))

  const server = new ApolloServer({
    typeDefs: [rootSchema, ...schemaTypes],
    resolvers: merge({
      Query: {
        myCat() {
          return {name: 'Zangief'}
        }
      }
    }, product, coupon, user),
    async context({ req }) {
      const user = await authenticate(req)
      return { user }
    }
  })

  await connect(config.dbUrl)
  const { url } = await server.listen({ port: config.port })

  console.log(`GQL server ready at ${url}`)
}

from intro-to-graphql.

laniehei avatar laniehei commented on August 24, 2024

Hi @LeeMellon, does the solution code to this exercise help at all? https://github.com/FrontendMasters/intro-to-graphql/blob/lesson-1-solution/src/server.js

from intro-to-graphql.

bilalds avatar bilalds commented on August 24, 2024

Going through the same lesson and also seeing this issue. There are slight differences in the code the instructor has in the first lesson vs the repo when you clone it.

from intro-to-graphql.

bilalds avatar bilalds commented on August 24, 2024

(node:14474) UnhandledPromiseRejectionWarning: Error: There can be only one type named "Query".

from intro-to-graphql.

bilalds avatar bilalds commented on August 24, 2024

Okay, my issue was resolved with installing bcrypt and running the mongodb server.

from intro-to-graphql.

enigmatikme avatar enigmatikme commented on August 24, 2024

same issue

from intro-to-graphql.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.