Skip to content

Commit

Permalink
Add new directive to test casing
Browse files Browse the repository at this point in the history
  • Loading branch information
smyrick committed Nov 16, 2023
1 parent 9d5c0cb commit e3da656
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "npm run dev:subgraphs & npm run dev:router",
"dev:subgraphs": "NODE_ENV=dev nodemon index.js",
"dev:router": "rover dev --supergraph-config supergraph-config-dev.yaml --router-config router-config-dev.yaml",
"dev:router": "rover dev --supergraph-config supergraph-config-dev.yaml --router-config router-config-dev.yaml --log error",
"start": "node index.js",
"test": "npm run test:compile && npm run test:compose",
"test:compose": "APOLLO_ELV2_LICENSE=accept rover supergraph compose --config supergraph-config-dev.yaml --output supergraph.graphql",
Expand Down
10 changes: 10 additions & 0 deletions router-config-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ headers:
request:
- propagate:
matching: .*

include_subgraph_errors:
all: true
telemetry:
apollo:
errors:
subgraph:
all:
send: true
redact: false
7 changes: 5 additions & 2 deletions subgraphs/flights/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.5", import:["@key", "@shareable"])
@link(url: "https://specs.apollo.dev/federation/v2.5", import:["@key", "@shareable", "@composeDirective"])
@composeDirective(name: "myAPI")

directive @myAPI on FIELD_DEFINITION

input MyDirectiveInput {
foo: String
bar: [String]
}

type Query {
allFlights: [Flight]
allFlights: [Flight] @myAPI
}

type Flight @key(fields: "id") {
Expand Down
8 changes: 7 additions & 1 deletion subgraphs/trips/resolvers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TRIPS } from "./data.js";
import {GraphQLError} from "graphql";

export const getTripById = (id) => TRIPS.find((it) => it.id === id);
export const getCurrentTripByUserId = (userId) => TRIPS.find((it) => it.user.id === userId);
Expand All @@ -11,7 +12,12 @@ export const resolvers = {
},
Query: {
currentTrip(_, args) {
return getCurrentTripByUserId(args.userId)
const trip = getCurrentTripByUserId(args.userId);
if (trip) {
return trip;
} else {
throw new GraphQLError(`No trip found for user id ${args.userId}`)
}
}
}
};
2 changes: 1 addition & 1 deletion subgraphs/trips/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key"])

type Query {
currentTrip(userId: ID!): Trip
currentTrip(userId: ID!): Trip!
}

type Trip @key(fields: "id") {
Expand Down

0 comments on commit e3da656

Please sign in to comment.