Skip to content

Commit

Permalink
chore(dev): buckify sdl updating / diffing
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Nov 7, 2023
1 parent 111bc19 commit ab9dd47
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ jobs:
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- uses: actions/checkout@v3
- run: nix develop -c buck2 run //dev:update-supergraph
- name: Run check code
run: nix develop -c buck2 test //dev:check-sdl
- run: nix develop -c buck2 test //dev:check-sdls
2 changes: 1 addition & 1 deletion ci/apps/app-template.lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ plan:
- { get: pipeline-tasks }
- task: #@ tilt_integration_test_name(app)
attempts: 2
timeout: 12m
timeout: 18m
tags: ["galoy-staging"]
config:
platform: linux
Expand Down
16 changes: 14 additions & 2 deletions core/api-keys/BUCK
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
load("@toolchains//rover:macros.bzl", "sdl")
load("@toolchains//rover:macros.bzl", "sdl", "diff_check", "dev_update_file")

sdl(
name = "sdl",
generator = ":write-sdl",
output = "subgraph/schema.graphql"
visibility = ["PUBLIC"],
)

diff_check(
name = "schema-diff",
original = "subgraph/schema.graphql",
new = ":sdl"
)

dev_update_file(
name = "update-schema",
generated = ":sdl",
out = "subgraph/schema.graphql"
)

rust_binary(
Expand Down
27 changes: 27 additions & 0 deletions core/api/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ load(
"yaml_check",
"madge_check",
)
load("@toolchains//rover:macros.bzl", "sdl", "diff_check")

dev_pnpm_task_binary(
name = "lint-fix",
Expand Down Expand Up @@ -79,6 +80,30 @@ prod_tsc_build_bin(
run_file = "servers/graphql-main-server.js",
)

export_file(
name = "public.schema",
src = "src/graphql/public/schema.graphql",
visibility = ["PUBLIC"],
)

diff_check(
name = "public-schema-diff",
original = ":public.schema",
new = ":public.schema"
)

export_file(
name = "admin.schema",
src = "src/graphql/admin/schema.graphql",
visibility = ["PUBLIC"],
)

diff_check(
name = "admin-schema-diff",
original = ":admin.schema",
new = ":admin.schema"
)

prod_tsc_build_bin(
name = "write-sdl",
run_file = "servers/write-sdl.js",
Expand Down Expand Up @@ -118,5 +143,7 @@ test_suite(
":check-type",
":check-yaml",
":check-circular-dependencies",
":public-schema-diff",
":admin-schema-diff",
],
)
2 changes: 1 addition & 1 deletion core/api/dev/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2024,4 +2024,4 @@ enum WalletCurrency

"""Unique identifier of a wallet"""
scalar WalletId
@join__type(graph: PUBLIC)
@join__type(graph: PUBLIC)
38 changes: 33 additions & 5 deletions dev/BUCK
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@toolchains//rover:macros.bzl", "supergraph", "diff_check", "dev_update_file")
load( ":tilt.bzl", "tilt_down", "tilt_up",)

# Bring up the full set of services for development
Expand All @@ -16,14 +17,41 @@ python_bootstrap_binary(
visibility = ["PUBLIC"],
)

sh_binary(
supergraph(
name = "supergraph",
config = "config/apollo-federation/supergraph-config.yaml",
subgraphs = {
"API_KEYS_SCHEMA": "//core/api-keys:sdl",
"PUBLIC_SCHEMA": "//core/api:public.schema",
},
)

diff_check(
name = "supergraph-diff",
original = "config/apollo-federation/supergraph.graphql",
new = ":supergraph"
)

test_suite(
name = "check-sdls",
tests = [
":supergraph-diff",
"//core/api:public-schema-diff",
"//core/api:admin-schema-diff",
"//core/api-keys:schema-diff",
],
)

dev_update_file(
name = "update-supergraph",
main = "bin/update-supergraph.sh",
generated = ":supergraph",
out = "config/apollo-federation/supergraph.graphql"
)

sh_test(
name = "check-sdl",
test = "bin/check-sdl.sh",
dev_update_file(
name = "update-core-supergraph",
generated = ":supergraph",
out = "../core/api/dev/apollo-federation/supergraph.graphql"
)

sh_binary(
Expand Down
15 changes: 0 additions & 15 deletions dev/bin/check-sdl.sh

This file was deleted.

20 changes: 0 additions & 20 deletions dev/bin/update-supergraph.sh

This file was deleted.

4 changes: 2 additions & 2 deletions dev/config/apollo-federation/supergraph-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ subgraphs:
public:
routing_url: http://bats-tests:4012/graphql
schema:
file: ../../../core/api/src/graphql/public/schema.graphql
file: ${env.PUBLIC_SCHEMA:-../../../core/api/src/graphql/public/schema.graphql}
api_keys:
routing_url: http://bats-tests:5397/graphql
schema:
file: ../../../core/api-keys/subgraph/schema.graphql
file: ${env.API_KEYS_SCHEMA:-../../../core/api-keys/subgraph/schema.graphql}
2 changes: 1 addition & 1 deletion dev/config/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2024,4 +2024,4 @@ enum WalletCurrency

"""Unique identifier of a wallet"""
scalar WalletId
@join__type(graph: PUBLIC)
@join__type(graph: PUBLIC)
5 changes: 5 additions & 0 deletions toolchains/rover/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ export_file(
name = "output_sdl.py",
visibility = ["PUBLIC"],
)

export_file(
name = "generate_supergraph.py",
visibility = ["PUBLIC"],
)
79 changes: 79 additions & 0 deletions toolchains/rover/generate_supergraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3
"""
Builds a portable, standalone npm binary.
"""
import argparse
import subprocess
import os
import sys
import json

def main(args):
# Check if the generator binary exists
rover_bin = args.rover_bin

# Prepare the environment variables from the subgraph argument
env = os.environ.copy()
for subgraph in args.subgraph:
key, path = subgraph.split('=')
absolute_path = os.path.abspath(path)
env[key] = absolute_path

# Run the generator binary and pass the out-path directly to the command
cmd = [
rover_bin,
"supergraph",
"compose",
"--config",
args.config,
"--output",
args.out_path, # The output path is passed directly to rover command
"--elv2-license",
"accept"
]

# Print out the command for debugging purposes
print("Running Command:")
print(' '.join(cmd))

try:
# Run the command without redirecting stdout since output is handled by rover itself
result = subprocess.run(cmd, stderr=subprocess.PIPE, text=True, env=env)

# Check if the generator command was successful
if result.returncode != 0:
print(f"Error: The generator binary failed to run with error:\n{result.stderr}")
sys.exit(result.returncode)

print(f"Success: Output written to {args.out_path}")

except Exception as e:
print(f"An error occurred: {e}")
sys.exit(1)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--rover-bin",
required=True,
help="Path to rover bin",
)
parser.add_argument(
"--config",
required=True,
help="Path to supergraph-config",
)
parser.add_argument(
"--subgraph",
action="append",
default=[],
help="Subgraph environment variables in the format ENV=path",
)
parser.add_argument(
"out_path",
help="Path to output the schema to",
)

args = parser.parse_args()
main(args)

Loading

0 comments on commit ab9dd47

Please sign in to comment.