Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faking graphql api using gaphql faker does not seem to query fields by id #150

Open
rosnk opened this issue Jun 3, 2021 · 0 comments
Open

Comments

@rosnk
Copy link

rosnk commented Jun 3, 2021

trying to create mock api using GraphQl faker.

Trying to achieve:

want to display categories (array list) on first render of app. and when user clicks particular category, want to call second graphql query to fetch products under that cateogry.

Basically trying to create fake graphql api to do so.

Current code

current schema:

type Picture {
  id: ID
  url: String @fake(type:imageUrl, options:{imageKeywords:["car", "bike","yatch","house"]})
}

type ProductItem {
  id: ID
  title: String @fake(type: productName)
  description: String @fake(type:lorem, options:{loremSize:paragraphs})
  picture: [Picture!]! 
}

 type Category {
  id: ID
  name: String
    @examples(
      values: [
        "car"
        "house"
        "electronics"
      ]
    )
  total: Int
  category_picture:String @fake(type:imageUrl, options:{imageKeywords:["car", "bike","yatch","house"]})
  category_items: [ProductItem!] @listLength(min: 2, max: 2)
  
}


type Query {
  allCategory: [Category!]
  productByItemId(id: ID!): ProductItem
  
} 

current query:


query{
  allCategory{
    id
    name
    category_picture
    category_items {
      id
    }
  }, 
  productByItemId(id:"NzAyMjA3ODg0MA==") {
    id
  }
}

output result:


{
  "data": {
    "allCategory": [
      {
        "id": "MzAwMzM3ODg0MQ==",
        "name": "electronics",
        "category_picture": "https://source.unsplash.com/random/?car,bike,yatch,house",
        "category_items": [
          {
            "id": "NzcyMDAwNzc4MA=="
          },
          {
            "id": "MzIwNjkzNzI4NQ=="
          }
        ]
      },
      {
        "id": "MzYwNzgyNDQ0",
        "name": "car",
        "category_picture": "https://source.unsplash.com/random/?car,bike,yatch,house",
        "category_items": [
          {
            "id": "ODkwNzEwODU5Nw=="
          },
          {
            "id": "MTQ3NjU2MTg5MA=="
          }
        ]
      },
      {
        "id": "MTI5NDM4MDc5OA==",
        "name": "house",
        "category_picture": "https://source.unsplash.com/random/?car,bike,yatch,house",
        "category_items": [
          {
            "id": "MjEzMjQyNDE4Mw=="
          },
          {
            "id": "MzAxOTM0NjMxNw=="
          }
        ]
      },
      {
        "id": "MzUzODk1NzY2Ng==",
        "name": "electronics",
        "category_picture": "https://source.unsplash.com/random/?car,bike,yatch,house",
        "category_items": [
          {
            "id": "MTMwODcyMDc2"
          },
          {
            "id": "NDQ5OTg2ODQ2Ng=="
          }
        ]
      }
    ],
    "productByItemId": {
      "id": "OTYyODEyNzYwNg=="
    }
  }
}

Problem

productByItemId(id:"NzAyMjA3ODg0MA==").... in this line that id is no where to be found.

I basically want to mock and use fake graphql api in my project...something like fetching category and also fetching products that matches id of particular category. Any solution is highly appreciated.... please also recommend any alternatives to graphql faker if there are any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant