octokit.graphql.net icon indicating copy to clipboard operation
octokit.graphql.net copied to clipboard

[WIP] Proof of concept auto-compiling, caching and argument passing to queries

Open jcansdale opened this issue 6 years ago • 0 comments

What this PR does

Allow the caching of compiled queries without any explicit caching or argument passing.

An example

Currently a developer might write their compiled query like this:

        static ICompiledQuery<string> getUserName;

        async Task<string> GetUserName(string login)
        {
            getUserName = getUserName ??
                new Query().User(Var(nameof(login))).Select(x => x.Name).Compile();

            var vars = new Dictionary<string, object>
            {
                { nameof(login), login }
            };

            return await Connection.Run(getUserName, vars);
        }

Which can be called using:

        var name = await GetUserName("jcansdale");

The alternative

This PR lets the developer write their query liks this:

        static IQueryableValue<string> GetUserNameQuery(Arg<string> login)
        {
            return new Query().User(login).Select(x => x.Name);
        }

The caching and argument passing is taken care of with a call like this:

        var name = await Connection.Run(GetUserNameQuery, "jcansdale");

Questions

Do you think something like this makes sense?

jcansdale avatar Jun 20 '18 22:06 jcansdale