Coder Social home page Coder Social logo

Comments (5)

tothandras avatar tothandras commented on July 19, 2024

Hi @tabakd!

The generated schema looks like this:

input addDeckInput {
  name: String
  slides: [ID]
  clientMutationId: String!
}

type addDeckPayload {
  viewer: Viewer
  changedDeckEdge: changedDeckEdge
  clientMutationId: String!
}

input addSlideInput {
  name: String
  component: String
  clientMutationId: String!
}

type addSlidePayload {
  viewer: Viewer
  changedSlideEdge: changedSlideEdge
  clientMutationId: String!
}

type changedDeck {
  name: String
  slides(after: String, first: Int, before: String, last: Int, name: String, _id: ID, component: String): slidesConnection
  _id: ID
  id: ID!
}

type changedDeckEdge {
  node: changedDeckNode
  cursor: String!
}

type changedDeckNode {
  name: String
  slides(after: String, first: Int, before: String, last: Int, name: String, _id: ID, component: String): slidesConnection
  _id: ID
  id: ID!
}

type changedSlide {
  name: String
  component: String
  _id: ID
  id: ID!
}

type changedSlideEdge {
  node: changedSlideNode
  cursor: String!
}

type changedSlideNode {
  name: String
  component: String
  _id: ID
  id: ID!
}

type Deck implements Node {
  name: String
  slides(after: String, first: Int, before: String, last: Int, name: String, _id: ID, component: String): slidesConnection
  _id: ID
  id: ID!
}

type DeckConnection {
  pageInfo: PageInfo!
  edges: [DeckEdge]
  count: Float
}

type DeckEdge {
  node: Deck
  cursor: String!
}

input deleteDeckInput {
  id: ID!
  clientMutationId: String!
}

type deleteDeckPayload {
  viewer: Viewer
  ok: Boolean
  id: ID!
  clientMutationId: String!
}

input deleteSlideInput {
  id: ID!
  clientMutationId: String!
}

type deleteSlidePayload {
  viewer: Viewer
  ok: Boolean
  id: ID!
  clientMutationId: String!
}

interface Node {
  id: ID!
}

type PageInfo {
  hasNextPage: Boolean!
  hasPreviousPage: Boolean!
  startCursor: String
  endCursor: String
}

type RootMutation {
  addDeck(input: addDeckInput!): addDeckPayload
  updateDeck(input: updateDeckInput!): updateDeckPayload
  deleteDeck(input: deleteDeckInput!): deleteDeckPayload
  addSlide(input: addSlideInput!): addSlidePayload
  updateSlide(input: updateSlideInput!): updateSlidePayload
  deleteSlide(input: deleteSlideInput!): deleteSlidePayload
}

type RootQuery {
  viewer: Viewer
  node(id: ID!): Node
  deck(id: ID!): Deck
  decks(id: [ID], ids: [ID], name: String, _id: ID): [Deck]
  slide(id: ID!): Slide
  slides(id: [ID], ids: [ID], name: String, component: String, _id: ID): [Slide]
}

type Slide implements Node {
  name: String
  component: String
  _id: ID
  id: ID!
}

type SlideConnection {
  pageInfo: PageInfo!
  edges: [SlideEdge]
  count: Float
}

type SlideEdge {
  node: Slide
  cursor: String!
}

type slidesConnection {
  pageInfo: PageInfo!
  edges: [slidesEdge]
  count: Float
}

type slidesEdge {
  node: Slide
  cursor: String!
}

input updateDeckInput {
  name: String
  slides: [ID]
  id: ID!
  clientMutationId: String!
}

type updateDeckPayload {
  changedDeck: changedDeck
  clientMutationId: String!
}

input updateSlideInput {
  name: String
  component: String
  id: ID!
  clientMutationId: String!
}

type updateSlidePayload {
  changedSlide: changedSlide
  clientMutationId: String!
}

type Viewer implements Node {
  id: ID!
  decks(after: String, first: Int, before: String, last: Int, name: String, _id: ID, component: String): DeckConnection
  deck(id: ID!): Deck
  slides(after: String, first: Int, before: String, last: Int, name: String, _id: ID, component: String): SlideConnection
  slide(id: ID!): Slide
}

You can also use the built in GraphiQL IDE to explore the schema.

_Add a new Deck:_

mutation AddDeck {
  addDeck(input: {clientMutationId: "1", name: "Deck"}) {
    changedDeckEdge {
      node {
        id
        name
        slides {
            edges {
            node {
              id
              name
              component
            }
          }
          count
        }
      }
    }
  }
}

The response is:

{
  "data": {
    "addDeck": {
      "changedDeckEdge": {
        "node": {
          "id": "RGVjazo1NjQxYWI3NGE1NjdjNjI2NWQ4OTljNDg=",
          "name": "Deck",
          "slides": {
            "edges": [],
            "count": 0
          }
        }
      }
    }
  }
}

_Add a slide:_

mutation AddSlide {
  addSlide(input: {clientMutationId: "2", name: "slide name", component: "slide component"}) {
    changedSlideEdge {
      node {
        id
        name
        component
      }
    }
  }
}

The response is:

{
  "data": {
    "addSlide": {
      "changedSlideEdge": {
        "node": {
          "id": "U2xpZGU6NTY0MWFjMzFhNTY3YzYyNjVkODk5YzRh",
          "name": "slide name",
          "component": "slide component"
        }
      }
    }
  }
}

_Using the slides id, we can change the slides of a deck to include it:_

mutation AddSlide {
  updateDeck(input: {clientMutationId: "3", id: "RGVjazo1NjQxYWI3NGE1NjdjNjI2NWQ4OTljNDg=", slides: ["U2xpZGU6NTY0MWFjMzFhNTY3YzYyNjVkODk5YzRh"]}) {
    changedDeck {
      name
      slides {
        count
        edges {
          node {
            id
            name
            component
          }
        }
      }
    }
  }
}

Response:

{
  "data": {
    "updateDeck": {
      "changedDeck": {
        "name": "Deck",
        "slides": {
          "count": 1,
          "edges": [
            {
              "node": {
                "id": "U2xpZGU6NTY0MWFjMzFhNTY3YzYyNjVkODk5YzRh",
                "name": "slide name",
                "component": "slide component"
              }
            }
          ]
        }
      }
    }
  }
}

There is no easier way currently to append an item to a list. We can add this feature request to our list, or you can send in a PR ;).

from graffiti-mongoose.

tabakd avatar tabakd commented on July 19, 2024

Hm. When I try to update the deck with a slide array it replaces all the slides rather than adds it to the list. Pull Request it is :) What piece of code should I be looking at?

from graffiti-mongoose.

tothandras avatar tothandras commented on July 19, 2024

Hi @tabakd! I've added support for appending elements to arrays, take a look at this PR: #73!

from graffiti-mongoose.

Secretmapper avatar Secretmapper commented on July 19, 2024

@tothandras Forgive me, I've been banging my head for a while here, but how would you do this with one mutation? As in add a slide to the database and add it to the array of slides as well?

from graffiti-mongoose.

tothandras avatar tothandras commented on July 19, 2024

@Secretmapper You can only do it using two mutations. First you create a slide, then for the other mutation you need to use the returned id of that newly included slide to add it to a collection.

from graffiti-mongoose.

Related Issues (20)

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.