Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/manojtharindu11/graphql

This repository consist of simple GraphQL concepts like create typeDefs, resolvers and mutaions using JavaScript.
https://github.com/manojtharindu11/graphql

apollo-server graphql mutations query

Last synced: 10 days ago
JSON representation

This repository consist of simple GraphQL concepts like create typeDefs, resolvers and mutaions using JavaScript.

Awesome Lists containing this project

README

        

# **GraphQL**

A brief summary of the GraphQL concepts I’ve explored:

### **1. Schema and Types**
Defines API structure using `Query`, `Mutation`, and custom types.
```graphql
type Game {
id: ID!,
title: String!,
platform: [String!]!
reviews: [Review!]
}
type Review {
id: ID!,
rating: Int!,
content: String!,
game: Game!,
author: Author!
}
type Author {
id: ID!,
name: String!,
verified: Boolean!,
reviews: [Review!]
}
```

### **2. Resolver Functions**
Fetches data for schema fields.
```javascript
Query: {
games() {
return db.games;
},
game(_, args) {
return db.games.find((game) => game.id === args.id);
},
reviews() {
return db.reviews;
},
review(_, args) {
return db.reviews.find((review) => review.id === args.id);
},
authors() {
return db.authors;
},
author(_, args) {
return db.authors.find((author) => author.id === args.id);
},
}
```

### **3. Query Variables**
Enable dynamic queries.
```graphql
query GamesQuery($id: ID!) {
game(id: $id) {
title,
platform,
reviews {
content,
rating
}
}}
```

### **4. Related Data**
Fetch nested relationships.
```graphql
type Game {
reviews: [Review!]
}
```

### **5. Mutations**
Perform data operations like add, update, or delete.
```graphql
mutation AddMutation($game: AddGameInput!) {
addGame(game: $game) {
id,
title,
platform
}
}
```