Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 902 Bytes

File metadata and controls

26 lines (21 loc) · 902 Bytes

Compiling Queries

In the quickstart we created a query and ran it directly on the connection:

var query = new Query().Viewer.Select(x => x.Login);
var productInformation = new ProductHeaderValue("YOUR_PRODUCT_NAME", "YOUR_PRODUCT_VERSION");
var connection = new Connection(productInformation, YOUR_OAUTH_TOKEN);
var result = await connection.Run(query);

This is fine for queries you only want to run once, but each time this query is run, the query expression needs to be parsed and the GraphQL query created. If you're going to be re-using a query it is better to compile the query and store it somewhere:

class MyService
{
    static readonly ICompiledQuery<string> myQuery = new Query()
        .Viewer
        .Select(x => x.Login)
        .Compile();
}

If you need to pass parameters to a compiled query, you can use variables.