Skip to content

Commit

Permalink
scary commit I can hardly recall
Browse files Browse the repository at this point in the history
  • Loading branch information
obrien-k committed Jul 25, 2023
1 parent 4524ba5 commit 162d3a1
Show file tree
Hide file tree
Showing 17 changed files with 260 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/apollographql/router:v1.10.0
FROM ghcr.io/apollographql/router:v1.15.1

ENV APOLLO_KEY=service:Marstronaut:k6cS2Ud2D7GznLDnslWwTw
ENV APOLLO_GRAPH_REF=Marstronaut@current
Expand Down
9 changes: 9 additions & 0 deletions apollo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
client: {
service: {
tagName: "gql",
name: "Marstronaut",
localSchemaFile: "./server/supergraph.graphql",
},
},
};
9 changes: 9 additions & 0 deletions client/apollo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
client: {
service: {
tagName: "gql",
name: "Marstronaut",
localSchemaFile: "../server/supergraph.graphql",
},
},
};
6 changes: 3 additions & 3 deletions client/src/components/xkcd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const comicNumber = Math.floor(Math.random() * (2645 - 1 + 1)) + 1;
console.log(comicNumber);

const GET_XKCD_COMIC = gql`
query xkcd($comicNumber: Int!) {
Comic(comic_number: $comicNumber) {
query xkcd($comicNumber: Int!, $testKey: String!) {
Comic(comic_number: $comicNumber) @connection(key: $testKey){
month
day
year
Expand All @@ -17,7 +17,7 @@ const GET_XKCD_COMIC = gql`

function XkcdData() {
const { loading, error, data } = useQuery(GET_XKCD_COMIC, {
variables: { comicNumber },
variables: { comicNumber, testKey: "somekey" },
});

if (loading) return null;
Expand Down
16 changes: 15 additions & 1 deletion client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@ import App from './App';
import reportWebVitals from './reportWebVitals';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';

const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
Comic: {
keyArgs: (args, { typename, field, fieldName, variables }) => {
return variables.testKey
},
},
},
},
},
})

const client = new ApolloClient({
uri: 'https://marstronaut-server.fly.dev',
cache: new InMemoryCache(),
cache: cache
});

document.body.style = 'background: #333;';
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '1'
services:
apollo-router:
container_name: apollo-router
build: apollographql/router:v1.10.0
container_name: mars-router
build: .
volumes:
- ./supergraph.graphql:/etc/config/supergraph.graphql
- ./router.yaml:/dist/config/router.yaml
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
"apollo-server": "^3.11.1",
"axios": "^0.27.2",
"concurrently": "^7.3.0",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"graphql": "^16.5.0",
"graphql": "^16.6.0",
"moment": "^2.29.4"
},
"devDependencies": {
Expand Down
21 changes: 21 additions & 0 deletions router.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,24 @@ supergraph:
# The socket address and port to listen on
listen: 0.0.0.0:4000
introspection: true
include_subgraph_errors:
all: true # Propagate errors from all subgraphs
headers:
all:
request:
- propagate:
matching: '.*'
- insert:
name: 'apollo-router-log-request'
value: 'my_client'
telemetry:
experimental_logging:
format: json # By default it's "pretty" if you are in an interactive shell session
display_filename: true # Display filename where the log is coming from. Default: true
display_line_number: false # Display line number in the file where the log is coming from. Default: true
# If one of these headers matches we will log supergraph and subgraphs requests/responses
when_header:
- name: apollo-router-log-request
value: my_client
headers: true # default: false
body: true # default: false
6 changes: 6 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ const server = new ApolloServer({
// Subscriptions are not currently supported in Apollo Federation
subscriptions: false,
context: async ({req}) => {
const faker = req.headers.faker || '';
if(faker) {
console.log(faker);
return {faker};
}
const token = req.headers.authorization || ''; // e.g., "Bearer user-1"
// Get the user token after "Bearer "
const id = token.split(' ')[1]; // e.g., "user-1"
console.log(id);
if (id) { // clean this up, assign userId to a var and start using real data
return {user: {userId: id, userRole:"test"}}
}
Expand Down
31 changes: 20 additions & 11 deletions server/subgraph-accounts/accounts.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ type Query {
Accounts: [Account]
"Find one Account based on ID"
Account(id: ID!): Account
Issue: Issue
}

type Mutation {
addAccount (id: ID!, role: String!): addAccountResponse!
}

type Order @key(fields: "account_id") {
account_id: ID!
type Order @key(fields: "id") {
id: ID!
total: Int @external
account_total_sales: Int @requires(fields:"total")
}
Expand All @@ -31,10 +28,22 @@ extend type Account @key(fields: "address_id") {
address_line_1: String
}

type addAccountResponse {
code: Int
success: Boolean
message: String
Account: Account
interface Rule {
id: ID!
name: String
}

type RuleA implements Rule {
id: ID!
name: String
}

type RuleB implements Rule {
id: ID!
name: String
}

type Issue {
id: ID
rule: [Rule]
}
4 changes: 4 additions & 0 deletions server/subgraph-accounts/datasources/accounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Accounts } = require(__dirname + '/accounts.json');
const { Issues } = require(__dirname + '/issues.json');
const fs = require('fs');

class AccountSource {
Expand Down Expand Up @@ -29,6 +30,9 @@ class AccountSource {
console.log(findAccount + 'findAccount returning undefined first attempt')
return findAccount;
}
getIssues() {
return Issues;
}
}

module.exports = AccountSource;
14 changes: 14 additions & 0 deletions server/subgraph-accounts/datasources/issues.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Issues":
[
{
"id": "141592",
"name": "no",
"Rule": "no"
},
{
"id": "1",
"Rule": "no"
}
]
}
3 changes: 3 additions & 0 deletions server/subgraph-accounts/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const resolvers = {
Accounts: async (_, __, {dataSources}) => {
return dataSources.AccountSource.getAccounts();
},
Issue: async (parent, {id}, context, info) => {
return context.dataSources.AccountSource.getIssues();
}
},
Account: {
__resolveReference: (reference, {dataSources}) => {
Expand Down
8 changes: 4 additions & 4 deletions server/subgraph-nasa/nasa.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Manifest {
photo_manifest: Photo_Manifest
}

type Photo_Manifest {
type Photo_Manifest @key (fields:"total_photos"){
"Name of the rover"
name: String
"Date when the rover landed on Mars"
Expand All @@ -29,12 +29,12 @@ type Photo_Manifest {
"The most recent Earth date from which photos exist"
max_date: String
"Number of photos taken by the rover"
total_photos: Int
total_photos: ID!
photos: [Photos!]!
}

type Photos {
sol: Int
type Photos @key (fields: "sol") {
sol: ID!
earth_date: String
total_photos: Int
cameras: [String]
Expand Down
9 changes: 7 additions & 2 deletions server/subgraph-orders/orders.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ type Query {
Order(id: ID!): Order
"Find all orders for an account"
AccountOrders(account_id: ID!): [Order]
"test"
inputTestQ (can: String!, I: Int!, Do: String!, It: String!, Like: String!, This: String!, HTL: Boolean!): inputTest
}

type Order @key(fields: "id") @key(fields:"account_id") {
type Order @key(fields:"id") {
id: ID!
account_id: ID!
total: Int
}

extend type Account @key(fields:"id") {
id: ID!
}

type inputTest {
id: ID
}
Loading

0 comments on commit 162d3a1

Please sign in to comment.