Skip to content

Extracting the SDL without running the app #4862

Answered by tobias-tengler
badsyntax asked this question in Q&A
Discussion options

You must be logged in to vote

You will not get around running your executable in some way. What you could do, is add a CLI argument to your application and if it's set just write the schema to a file and exit the application.

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddGraphQLServer();
   // ...

var app = builder.Build();

if (args.Any(a => a == "--export"))
{
    var executor = await app.Services
         .GetRequiredService<IRequestExecutorResolver>()
         .GetRequestExecutorAsync();

    string schema = executor.Schema.Print();

    // write it to a file, etc.
    return;
}

app.MapGraphQL();
// ...

Then you just need to run your application with the argument:

dotnet run -- --ex…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@badsyntax
Comment options

@ernestfolch
Comment options

@michaelstaib
Comment options

@badsyntax
Comment options

@ernestfolch
Comment options

Answer selected by badsyntax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants