Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnserrano15/graphql-backend
https://github.com/johnserrano15/graphql-backend
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/johnserrano15/graphql-backend
- Owner: johnserrano15
- License: mit
- Created: 2019-08-08T22:02:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T01:20:54.000Z (about 2 years ago)
- Last Synced: 2024-04-15T03:00:05.041Z (8 months ago)
- Language: JavaScript
- Size: 485 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Queries ejecutadas en el curso en GraphiQL
## Get all courses
```graphql
{
getCourses {
title
description
}
}
```## Get course ID
```graphql
{
getCourse(id: "oqeded2") {
_id
title
description
}
}
```## Mutation
```graphql
mutation {
createCourse(input: {
title: "Nuevo curso"
description: "Description new"
topic: "diseño"
}){
_id
title
description
}
}
```## Mutation Edit
```graphql
mutation {
editCourse(_id: "5d499e87f05e5225c8c93db0", input: {
title: "Curso editado"
teacher: "John Serrano"
}){
title
teacher
}
}
```## Mutation Delete
```graphql
mutation {
deleteCourse(_id: "5d49a689956e731fb00367f1")
}
```## Mutation Nested Types
```graphql
mutation {
addPeople(courseID: "5d49935b7389141d5c7c7172",
personID: "5d49a82087948f2aac0a3b0a"){
_id
title
}
}
```## Resolver types
```graphql
{
getCourses {
_id
title
description
teacher
people {
_id
name
}
}
}
```## Alias
```graphql
{
AllCourses: getCourses {
_id
title
description
}
Course1: getCourse(id: "5d4993c93b833e1d5c0929d0"){
title
description
}
Course2: getCourse(id: "5d499e87f05e5225c8c93db0"){
title
description
topic
}
Course3: getCourse(id: "5d499e87f05e5225c8c93db0"){
title
description
people {
name
}
}
}
```## Fragment
```graphql
{
AllCourses: getCourses {
...CourseFields
}
Course1: getCourse(id: "5d4993c93b833e1d5c0929d0"){
...CourseFields
teacher
}
Course2: getCourse(id: "5d499e87f05e5225c8c93db0"){
...CourseFields
topic
}
}fragment CourseFields on Course {
_id
title
description
people {
_id
name
}
}
```## Variables
```graphql
query GetCourse2 ($course: ID!) {
getCourse(id: $course){
_id
title
people{
_id
name
}
}
}
```* Requiere un objeto JSON como:
```json
{
"course": "5cb4b8ce75f954a0585f7be3"
}
```
---```graphql
mutation AddPersonToCourse ($course: ID!, $person: ID!){
addPeople(courseID: $course, personID: $person) {
_id
title
}
}
```* Requiere un objeto JSON como:
```json
{
"course": "5d499e87f05e5225c8c93db0",
"person": "5d49a82087948f2aac0a3b0a"
}
```## Enums
```graphql
mutation CreateNewCourse($createInput: CourseInput!) {
createCourse(input: $createInput) {
title
description
}
}
```* Requiere un objeto JSON como:
```json
{
"createInput": {
"title": "Course new example",
"teacher": "My teacher",
"description": "my description",
"topic": "marketing",
"level": "principiante"
}
}
```## Interfaces - Tipo Monitor
``` graphql
mutation CreateNewMonitor($createInput: PersonInput!) {
createPerson(input: $createInput){
_id
name
}
}
``````graphql
{
getPeople {
_id
name
... on Monitor {
phone
}
}
}
```## Directivas @include and @skip
``` graphql
query getPeopleDate($monitor: Boolean!) {
getPeople {
_id
name
... on Monitor @include(if: $monitor){
phone
}
}
}query getPeopleDate($monitor: Boolean!, $avatar: Boolean!) {
getPeople {
_id
name
... on Monitor @include(if: $monitor){
phone
}
... on Student @skip(if: $avatar){
avatar
}
}
}
```* Requiere un objeto JSON como:
```json
{
"monitor": false,
"avatar": false
}
```## Unions
``` graphql
{
searchItems(keyword: "title") {
__typename
... on Course {
_id
title
description
}
... on Monitor {
_id
name
}
... on Student {
_id
name
}
}
}
```> *Nota se crearon los indexes -> `db.courses.createIndex({ "$**": "text" }); db.students.createIndex({ "$**": "text" });`*