Skip to content

Commit

Permalink
feat(2639): implement entity resolver (#2693)
Browse files Browse the repository at this point in the history
Co-authored-by: Tushar Mathur <[email protected]>
Co-authored-by: Amit Singh <[email protected]>
  • Loading branch information
3 people authored Sep 24, 2024
1 parent b0bcfcf commit c062058
Show file tree
Hide file tree
Showing 64 changed files with 5,474 additions and 381 deletions.
21 changes: 21 additions & 0 deletions examples/apollo_federation_subgraph_post.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
schema
@server(port: 8001)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 100}) {
query: Query
}

type Query {
posts: [Post] @http(path: "/posts")
}

type User @http(path: "/users", query: [{key: "id", value: "{{.value.id}}"}], batchKey: ["id"]) {
id: Int!
}

type Post @http(path: "/posts", query: [{key: "id", value: "{{.value.id}}"}], batchKey: ["id"]) {
id: Int!
userId: Int!
title: String!
body: String!
user: User @expr(body: {id: "{{.value.userId}}"})
}
18 changes: 18 additions & 0 deletions examples/apollo_federation_subgraph_user.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
schema
@server(port: 8002)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 100}) {
query: Query
}

type Query {
user(id: Int!): User @http(path: "/users/{{.args.id}}")
}

type User @http(path: "/users", query: [{key: "id", value: "{{.value.id}}"}], batchKey: ["id"]) {
id: Int!
name: String
username: String
email: String
phone: String
website: String
}
28 changes: 28 additions & 0 deletions examples/federation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Apollo Federation example

1. Start tailcall subgraph examples:

- `cargo run -- start examples/apollo_federation_subgraph_post.graphql`
- `cargo run -- start examples/apollo_federation_subgraph_user.graphql`

2. Run Apollo router by one of the following methods:

- run `@apollo/gateway` with `npm start` (with `npm install` for the first time) from "examples/federation" folder
- start apollo router with `rover.sh` script (install [apollo rover](https://www.apollographql.com/docs/rover) first)

3. Navigate to `http://localhost:4000` and execute supergraph queries, see [examples](#query-examples)

# Query examples

```graphql
{
posts {
id
title
user {
id
name
}
}
}
```
20 changes: 20 additions & 0 deletions examples/federation/gateway.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {ApolloServer} from "@apollo/server"
import {startStandaloneServer} from "@apollo/server/standalone"
import {ApolloGateway, IntrospectAndCompose} from "@apollo/gateway"

const gateway = new ApolloGateway({
supergraphSdl: new IntrospectAndCompose({
subgraphs: [
{name: "post", url: "http://localhost:8001/graphql"},
{name: "user", url: "http://localhost:8002/graphql"},
],
}),
})

const server = new ApolloServer({
gateway,
introspection: true,
})

const {url} = await startStandaloneServer(server)
console.log(`🚀 Server ready at ${url}`)
Loading

1 comment on commit c062058

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 11.66ms 4.61ms 129.84ms 87.82%
Req/Sec 2.18k 265.38 2.92k 85.33%

260480 requests in 30.03s, 1.31GB read

Requests/sec: 8675.13

Transfer/sec: 44.53MB

Please sign in to comment.