Skip to content

Instantly share code, notes, and snippets.

@jonathanbernal25
Last active September 4, 2020 07:50
Show Gist options
  • Save jonathanbernal25/9968d0f3b2f95cf800a71cece85a18f9 to your computer and use it in GitHub Desktop.
Save jonathanbernal25/9968d0f3b2f95cf800a71cece85a18f9 to your computer and use it in GitHub Desktop.
Tyk's Universal Data Graph (UDG) Example

1. Fetch a user

Schema Editor
type Query {
  user(id: Int!): User 
}
type User {
  id: Int
  name: String
  email: String
}
Playground Query
query{
  user(id: 1){
    id
    name
    email
    }
}
Define Data Source

https://jsonplaceholder.typicode.com/users/{{.arguments.id}}

2. Fetch the posts

Schema Editor
type Query {
  user(id: Int!): User
}
type User {
  id: Int
  name: String
  email: String
  posts: [Post]
}
type Post {
  id: Int
  title: String
  body: String
}
Playground Query
query{
  user(id: 1){
    id
    name
    email
    posts{
      id
      title
      body
      }
    }
}
Define Data Source

https://jsonplaceholder.typicode.com/posts?userId={{.object.id}}

3. Fetch the comments

Schema Editor
type Query {
  user(id: Int!): User
}
type User {
  id: Int
  name: String
  email: String
  posts: [Post]
}
type Post {
  id: Int
  title: String
  body: String
  comments: [Comment]
}
type Comment {
  id: Int
  name: String
  email: String
  body: String
}
Playground Query
query{
  user(id: 1){
    id
    name
    email
    posts{
      id
      title
      body
      comments{
        id
        name
        email
        body
        }
      }
   }
}
Define Data Source

https://jsonplaceholder.typicode.com/comments?postId={{.object.id}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment