Skip to content

johnserrano15/graphql-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Queries ejecutadas en el curso en GraphiQL

Get all courses

{
  getCourses {
    title
    description
  }
}

Get course ID

{
  getCourse(id: "oqeded2") {
    _id
    title
    description
  }
}

Mutation

mutation {
  createCourse(input: {
   	title: "Nuevo curso"
    description: "Description new"
    topic: "diseño"
  }){
    _id
    title
    description
  }
}

Mutation Edit

mutation {
  editCourse(_id: "5d499e87f05e5225c8c93db0", input: {
    title: "Curso editado"
    teacher: "John Serrano"
  }){
    title
    teacher
  }
}

Mutation Delete

mutation {
  deleteCourse(_id: "5d49a689956e731fb00367f1")
}

Mutation Nested Types

mutation {
  addPeople(courseID: "5d49935b7389141d5c7c7172", 
    personID: "5d49a82087948f2aac0a3b0a"){
    _id
    title
  }
}

Resolver types

{
  getCourses {
    _id
    title
    description
    teacher
    people {
      _id
      name
      email
    }
  }
}

Alias

{
  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
      email
    }
  }
}

Fragment

{
  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

query GetCourse2 ($course: ID!) {
  getCourse(id: $course){
   _id
    title
    people{
      _id
      name
    }
  }
}
  • Requiere un objeto JSON como:
{
  "course": "5cb4b8ce75f954a0585f7be3"
}

mutation AddPersonToCourse ($course: ID!, $person: ID!){
  addPeople(courseID: $course, personID: $person) {
    _id
    title
  }
}
  • Requiere un objeto JSON como:
{
  "course": "5d499e87f05e5225c8c93db0",
  "person": "5d49a82087948f2aac0a3b0a"
}

Enums

mutation CreateNewCourse($createInput: CourseInput!) {
  createCourse(input: $createInput) {
    title
    description
  }
}
  • Requiere un objeto JSON como:
{
  "createInput": {
    "title": "Course new example",
    "teacher": "My teacher",
    "description": "my description",
    "topic": "marketing",
    "level": "principiante"
  }
}

Interfaces - Tipo Monitor

mutation CreateNewMonitor($createInput: PersonInput!) {
  createPerson(input: $createInput){
    _id
    name
  }
}
{
  getPeople {
    _id
    name
    email
    ... on Monitor {
      phone
    }
  }
}

Directivas @include and @skip

query getPeopleDate($monitor: Boolean!) {
  getPeople {
    _id
    name
    email
    ... 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
      email
    }
  }
}
  • Requiere un objeto JSON como:
{
  "monitor": false,
  "avatar": false
}

Unions

{
  searchItems(keyword: "title") {
    __typename
    ... on Course {
      _id
      title
      description
    }
    ... on Monitor {
      _id
      name
      email
    }
    ... on Student {
      _id
      name
      email
    }
  }
}

Nota se crearon los indexes -> db.courses.createIndex({ "$**": "text" }); db.students.createIndex({ "$**": "text" });

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published