MCPcopy Index your code
hub / github.com/TomDoesTech/TypeGraphQL-Typegoose-GraphQL-Tutorial

github.com/TomDoesTech/TypeGraphQL-Typegoose-GraphQL-Tutorial @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
41 symbols 72 edges 17 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

GraphQL API with TypeGraphQL, TypeGoose & TypeScript

What technology are we using?

Who is this tutorial for?

  • Those familiar with NodeJs
  • Those wanting to learn GraphQL
  • Those wanting to learn TypeScript

I don't know GraphQL, should I watch this video?

  • TypeGraphQL is to GraphQL what TypeScript is to JavaScript
  • You might get a bit confused, the syntax used is weird
  • You should get a basic understanding of GraphQL first
  • I'll do a walk-through and explain the code first

Why TypeGraphQL?

TypeGraphQL reduced boilerplate. Without it, you have to update schema, data models, resolvers & type definitions. With TypeGraphQL, you only need to update resolvers and data models.

WTF is an decorator?

A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use the form @expression, where expression must evaluate to a function that will be called at runtime with information about the decorated declaration.

Reference: https://www.typescriptlang.org/docs/handbook/decorators.html#accessor-decorators


Queries & mutations

Create user

Query

mutation createUser($input: CreateUserInput!){
  createUser(input: $input) {
    email
    _id
    name
  }
}

Input

{
  "input": {
    "email": "1@example.com",
    "name": "Jane Doe",
    "password": "password"
  }
}

Get current user

Query

query {
  me {
    _id
    name
    email
  }
}

Login

Query

mutation login($input: LoginInput!){
  login(input: $input) 
}

Input

{
  "input": {
    "email": "1@example.com",
    "password": "password"
  }
}

Create a product

Query

mutation createProduct($input: CreateProductInput!){
  createProduct(input: $input){
    _id
    price
    productId
    name
    description
  }
}

Input

{
  "input": {
    "name": "A test product111",
    "description": "blah blah blah blah blah blahblah blah blahblah blah blahblah blah blahblah blah blahblah blah blah",
    "price": 24.99

  }
}

Get products

query products {
  products {
    productId
    name
    description
    productId
  }
}

Get a single product

Query

query product($input: GetProductInput!) {
  product(input: $input) {
    _id
    productId
    price
    name
    description
  }
}

Input

{
  "input": {
    "productId": "product_23cn3k61h8"
  }
}

Extension points exported contracts — how you extend this code

Context (Interface)
(no doc)
src/types/context.ts
QueryHelpers (Interface)
(no doc)
src/schema/user.schema.ts

Core symbols most depended-on inside this repo

bootstrap
called by 1
src/index.ts
connectToMongo
called by 1
src/utils/mongo.ts
signJwt
called by 1
src/utils/jwt.ts
verifyJwt
called by 1
src/utils/jwt.ts
findProducts
called by 1
src/service/product.service.ts
findSingleProduct
called by 1
src/service/product.service.ts
authChecker
called by 0
src/utils/authChecker.ts
createUser
called by 0
src/service/user.service.ts

Shape

Class 20
Method 13
Function 6
Interface 2

Languages

TypeScript100%

Modules by API surface

src/schema/user.schema.ts8 symbols
src/schema/product.schema.ts6 symbols
src/resolvers/user.resolver.ts6 symbols
src/resolvers/product.resolver.ts6 symbols
src/service/product.service.ts5 symbols
src/service/user.service.ts4 symbols
src/utils/jwt.ts2 symbols
src/utils/mongo.ts1 symbols
src/utils/authChecker.ts1 symbols
src/types/context.ts1 symbols
src/index.ts1 symbols

Datastores touched

(mongodb)Database · 1 repos
graphql-api-tutorialDatabase · 1 repos

For agents

$ claude mcp add TypeGraphQL-Typegoose-GraphQL-Tutorial \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact