diff --git a/.github/workflows/apollo-check.yml b/.github/workflows/apollo-check.yml new file mode 100644 index 0000000..867c22d --- /dev/null +++ b/.github/workflows/apollo-check.yml @@ -0,0 +1,24 @@ +name: Apollo Check +on: + pull_request: +jobs: + build: + runs-on: ubuntu-latest + env: + APOLLO_VCS_BRANCH: ${{ github.head_ref }} + APOLLO_VCS_COMMIT: ${{ github.event.pull_request.head.sha }} + steps: + - uses: actions/checkout@v4 + - uses: apollographql-gh-actions/install-rover@v1 + - uses: apollographql-gh-actions/rover-subgraph-lint@v1 + with: + apollo-key: ${{ secrets.APOLLO_KEY }} + graph-ref: ${{ secrets.APOLLO_GRAPH_REF }} + name: github + schema: ./github.graphql + - uses: apollographql-gh-actions/rover-subgraph-check@v1 + with: + apollo-key: ${{ secrets.APOLLO_KEY }} + graph-ref: ${{ secrets.APOLLO_GRAPH_REF }} + name: github + schema: ./github.graphql diff --git a/.github/workflows/apollo-publish.yml b/.github/workflows/apollo-publish.yml new file mode 100644 index 0000000..774bc27 --- /dev/null +++ b/.github/workflows/apollo-publish.yml @@ -0,0 +1,19 @@ +name: Apollo Publish +on: + push: + branches: + - main +jobs: + build: + runs-on: ubuntu-latest + environment: apollo + steps: + - uses: actions/checkout@v4 + - uses: apollographql-gh-actions/install-rover@v1 + - uses: apollographql-gh-actions/rover-subgraph-publish@v1 + with: + apollo-key: ${{ secrets.APOLLO_KEY }} + graph-ref: ${{ secrets.APOLLO_GRAPH_REF }} + name: github + schema: ./github.graphql + no-url: true diff --git a/github.graphql b/github.graphql new file mode 100644 index 0000000..0c01e6f --- /dev/null +++ b/github.graphql @@ -0,0 +1,43 @@ +extend schema + @link(url: "https://specs.apollo.dev/federation/v2.10", import: ["@key"]) + @link( + url: "https://specs.apollo.dev/connect/v0.1" + import: ["@connect", "@source"] + ) + @source( + name: "github" + http: { + baseURL: "https://api.github.com" + headers: [ + { name: "Accept", value: "application/vnd.github+json" } + { name: "User-Agent", value: "{$config.agent}" } + { name: "Authorization", value: "token {$config.token}" } + ] + } + ) + +type Query { + "All trees in the leetcode-study repository" + gitTrees: [GitTree]! + @connect( + source: "github" + # https://docs.github.com/en/rest/git/trees#get-a-tree + http: { + GET: "/repos/DaleStudy/leetcode-study/git/trees/main?recursive=1" + } + selection: """ + $.tree { + type + path + } + """ + ) +} + +"A file or directory in the Git repository" +type GitTree { + "The type of the node" + type: String! + "The path of the node" + path: String! +} diff --git a/products.graphql b/products.graphql deleted file mode 100644 index cda65e2..0000000 --- a/products.graphql +++ /dev/null @@ -1,58 +0,0 @@ -# This schema uses Apollo Connectors, a declarative programming model for -# GraphQL that allows you to plug in your existing REST services directly into -# a graph. To learn more, visit Apollo's documentation: 🔗https://www.apollographql.com/docs/graphos/schema-design/connectors - -# Guided tutorial: 🔗 https://www.apollographql.com/docs/graphos/get-started/guides/rest - -extend schema - @link( # Enable this schema to use Apollo Federation features - url: "https://specs.apollo.dev/federation/v2.10" - ) - @link( # Enable this schema to use Apollo Connectors - url: "https://specs.apollo.dev/connect/v0.1" - import: ["@connect", "@source"] - ) - -# A @source directive defines a shared data source for multiple Connectors. -# ✏️ Replace the `name` and `baseURL` of this @source with your own REST API. -@source( - name: "ecomm" - # A @source directive defines a shared data source for multiple Connectors. - http: { - baseURL: "https://ecommerce.demo-api.apollo.dev/" - headers: [ - # If your API requires headers, add them here and in your router.yaml file. - { name: "name", value: "{$config.apiKey}" } - ] - } -) - -# ✏️ Replace this example type with your own object type. -type Product { - id: ID! - name: String - description: String -} - -# ✏️ Set up your Query field with the endpoint that returns the data you want. - -type Query { - # The Query.products field uses @connect to connect to the /products endpoint in the "ecomm" source. - # To check out the JSON response for this endpoint, go to 🔗 https://ecommerce.demo-api.apollo.dev/products. - products: [Product] - # A @connect directive defines the API data source of a GraphQL schema field. - @connect( - source: "ecomm" - http: { GET: "/products" } # GET, POST, PUT, PATCH, DELETE. - # Use @connect for any field that should be resolved by your REST API endpoints. - # Use the selection argument to map fields from the JSON response to the type. - # You can do more with this selection mapping. Lean more at 🔗 https://www.apollographql.com/docs/graphos/schema-design/connectors/responses - selection: """ - $.products { - id - name - description - } - """ - ) -}