0
0
GraphQLquery~20 mins

Subgraph definition in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Subgraph Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this subgraph query?

Given this subgraph schema and query, what will be the result?

type Product @entity {
  id: ID!
  name: String!
  price: Int!
}

query {
  products {
    id
    name
  }
}
GraphQL
schema {
  query: Query
}

type Query {
  products: [Product!]!
}

type Product @entity {
  id: ID!
  name: String!
  price: Int!
}

query {
  products {
    id
    name
  }
}
A[{"id": "1", "name": "Apple"}, {"id": "2", "name": "Banana"}]
B[{"id": "1", "name": "Apple", "price": 100}, {"id": "2", "name": "Banana", "price": 50}]
C[{"id": "1"}, {"id": "2"}]
D[]
Attempts:
2 left
💡 Hint

The query only asks for id and name, so price is not included in the output.

📝 Syntax
intermediate
2:00remaining
Which option contains a syntax error in subgraph definition?

Identify the option that has a syntax error in the GraphQL subgraph schema definition.

GraphQL
type User @entity {
  id: ID!
  username: String!
  email: String!
}
A
type User @entity {
  id: ID!
  username: String!
  email: String!
}
B
type User @entity {
  id: ID!
  username: String!
  email: String
}
C
type User @entity {
  id: ID!
  username: String!
  email: String!
D
type User @entity {
  id: ID!
  username: String!
  email: String!
  age: Int
}
Attempts:
2 left
💡 Hint

Check for missing closing braces or punctuation.

optimization
advanced
2:00remaining
Which subgraph query is optimized to fetch only needed data?

You want to fetch only the id and title of posts from a subgraph. Which query is optimized?

GraphQL
type Post @entity {
  id: ID!
  title: String!
  content: String!
  author: User!
}
A
query {
  posts {
    id
  }
}
B
query {
  posts {
    id
    title
    content
  }
}
C
query {
  posts {
    id
    author {
      id
    }
  }
}
D
query {
  posts {
    id
    title
  }
}
Attempts:
2 left
💡 Hint

Only request the fields you need to reduce data transfer.

🔧 Debug
advanced
2:00remaining
Why does this subgraph query return an empty list?

Given this subgraph schema and query, why does the query return an empty list?

type Book @entity {
  id: ID!
  title: String!
  author: String!
}

query {
  books(where: {author: "Unknown"}) {
    id
    title
  }
}
GraphQL
type Book @entity {
  id: ID!
  title: String!
  author: String!
}

query {
  books(where: {author: "Unknown"}) {
    id
    title
  }
}
AThe query is missing the 'id' field, so no results are returned.
BThere are no books with author exactly "Unknown" in the data.
CThe 'author' field is not indexed, so filtering is not supported.
DThe 'where' filter syntax is invalid and causes the query to fail silently.
Attempts:
2 left
💡 Hint

Check if the data contains any matching entries for the filter.

🧠 Conceptual
expert
2:00remaining
What is the main purpose of a subgraph in a GraphQL architecture?

Choose the best explanation for the role of a subgraph in a GraphQL system.

AA subgraph defines a part of the overall schema and data, allowing modular and scalable GraphQL services.
BA subgraph is a client-side cache that stores query results for faster access.
CA subgraph is a database table that stores GraphQL queries and mutations.
DA subgraph is a tool to convert REST APIs into GraphQL automatically.
Attempts:
2 left
💡 Hint

Think about how large GraphQL schemas are managed in parts.