#graphql Explorer?

1 messages Β· Page 1 of 1 (latest)

copper trail
#

I know we can make graphql queries via the cli, but I'm wondering if there is an official way to use a graphql explorer with dagger?

https://docs.dagger.io/api/http#dagger-cli

I've used graphql on backend servers in the past and having the visual UI to explore the schema was helpful. Is that possible with dagger?

The Dagger API is an HTTP API that uses GraphQL as its low-level language-agnostic framework. Therefore, it's possible to call the Dagger API using raw HTTP queries, from any language that supports GraphQL. GraphQL has a large and growing list of client implementations in over 20 languages.

molten widget
#

@copper trail yes! if you run DAGGER_SESSION_TOKEN=foo dagger listen --allow-cors --listen 0.0.0.0:8080 that will start a local graphql server that you can access with any graphql client explorer

#

and you need to supply a basic auth header with the username being the session token

copper trail
#

Thanks.

I did have to base64 encode the "foo" username to get it to work as the Authorization header

Authorization Basic Zm9vOg==

One remaining question though is that I'm getting a 401 Error when trying to execute a custom dagger function:

Here's what I'm seeing in claude desktop

{
  `query`: `
{
  directory {
    withNewFile(path: "main.go", contents: "package main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hello, World!\")\n}\n") {
      withNewFile(path: "main_test.go", contents: "package main\n\nimport \"testing\"\n\nfunc TestMain(t *testing.T) {\n    // Simple test\n    if 1+1 != 2 {\n        t.Error(\"Math is broken\")\n    }\n}\n") {
        withNewFile(path: "go.mod", contents: "module hello\n\ngo 1.21\n") {
          id
        }
      }
    }
  }
}
`
}
{"data":null,"errors":[{"message":"HTTP fetch failed from 'dagger': 401: Unauthorized","path":[],"extensions":{"code":"SUBREQUEST_HTTP_ERROR","service":"dagger","reason":"401: Unauthorized","http":{"status":401}}},{"message":"HTTP fetch failed from 'dagger': subgraph response does not contain 'content-type' header; expected content-type: application/json or content-type: application/graphql-response+json","path":[],"extensions":{"code":"SUBREQUEST_HTTP_ERROR","service":"dagger","reason":"subgraph response does not contain 'content-type' header; expected content-type: application/json or content-type: application/graphql-response+json","http":{"status":401}}}]}

Does this mean I'd need to also config my MCP server to send along the Authorization header somehow?

^^

#

I am trying to get the graphql wired up to the apollo mcp server with a few things working. I can't seem to execute any custom functions though.

https://www.apollographql.com/docs/apollo-mcp-server/quickstart

I output the schema with rover via:

cd ~/projects/hello-go
rover graph introspect http://localhost:8080/query \
  --header "Authorization: Basic Zm9vOg==" \
  --output schema.graphql

I can then create a supergraph.yml

federation_version: 2
subgraphs:
  dagger:
    routing_url: http://localhost:8080/query
    schema:
      file: ./schema.graphql

Then I can get the apollo mcp server running via:

rover dev --supergraph-config ./supergraph.yaml \
  --mcp --mcp-port 5000 \
  --mcp-header "Authorization: Basic Zm9vOg==" \
  --mcp-introspection
copper trail
#

hmmm, in looking more closely at the query that claude generated for the the mcp tests, I'm actually not sure where that came from. I don't have tests like that anywhere. Looks like that was potentially hallucinated.

I'm thinking that feeding the entire schema to the apollo mcp server may not be the idea approach here

molten widget
copper trail
#

Ha, sorry, I kind of got myself lost in there as well πŸ™‚

I wanted to document my journey in case anyone else comes across this and finds it useful but ended up cluttering the overall message.

Mostly this is just a exploration for me trying to grok how dagger graphql schema is setup and works, but thought it would be useful to also explore the apollo graphql MCP at the same time.

Here is the repo I'm working from: https://github.com/justinlevi/hello-go

**My goals are: **

  1. execute a custom dagger function I have in my project via the graphql explorer.

  2. execute the same dagger function via my MCP connection to the apollo MCP server from claude desktop

Here are the functions I have:

 hello-go git:(main)βœ—  πŸš€ dagger functions           
β–Ά connect 0.2s
β–Ά load module: . 0.4s

Name             Description
build            Build creates binaries for multiple
...
test             Test runs tests with race detection and coverage
vet              Vet runs go vet for static analysis
 hello-go git:(main)βœ—  πŸš€ 

Here I can run the test function via:

hello-go git:(main)  πŸš€ dagger call test --source .    
β–Ά connect 0.9s
β–Ά load module: . 0.4s
● parsing command line arguments 0.2s

● helloGo: HelloGo! 0.0s
β–Ά .test(
  ┆ source: Host.directory(path: "/Users/jwinter/projects/hello-go"): Directory!
  ): String! 7.0s

Coverage: 63.4%

How can I translate: dagger call test --source . into a graphql query I could execute via graphql explorer?

#

oh wow, I think I kind of figured it out...

Step 1. Get the directory ID

query GetSourceDirectory {
  host {
    directory(path: ".") {
      id
    }
  }
}

Step 2: Execute the test with the Directory ID

query RunTest($sourceDir: DirectoryID!) {
  helloGo {
    test(source: $sourceDir)
  }
}

Is this the best way to do this?

copper trail
molten widget
molten widget
raw herald
#

@copper trail one quick note: you don't actually need to base64-encode the token

#

you can simply use the token as the username in the url, with an empty password:

rover graph introspect http://foo:@localhost:8080/query