-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sample does not rock #193
Comments
It looks like the problem is here: static void Main(string[] args)
{
AsyncMethodAsync();
} You need to wait for the using Octokit.GraphQL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static Octokit.GraphQL.Variable;
namespace ConsoleGitHubGraphQL
{
class Program
{
static async Task Main(string[] args)
{
await AsyncMethodAsync();
}
static async Task AsyncMethodAsync()
{
// The product name is either the product, the GitHub
// Organization, or the GitHub username.
var productInformation = new ProductHeaderValue("SimpleSamples" /*, "YOUR_PRODUCT_VERSION"*/);
var connection = new Connection(productInformation, "YOUR PERSONAL ACCESS TOKEN");
var query = new Query()
.RepositoryOwner(Var("owner"))
.Repository(Var("name"))
.Select(repo => new
{
repo.Id,
repo.Name,
repo.Owner.Login,
repo.IsFork,
repo.IsPrivate,
}).Compile();
var vars = new Dictionary<string, object>
{
{ "owner", "github" },
{ "name", "VisualStudio" },
};
var result = await connection.Run(query, vars);
Console.WriteLine(result.Login + " & " + result.Name + " Rocks!");
}
}
} |
Alternatively you could do:
If you're compiling for an older version of C#. |
I'm closing this because I believe a missing |
I apologize for not saying that the sample code is from Bringing GraphQL to Octokit.NET except it has problems that I attempted to fix. Is that article within the scope of here? Note that the message at the bottom of that sample says "Rocks" and that is why I made the title of this "Sample does not rock". That sample has a:
That does not work or at least is not necessary. The sample also says Connection.Run instead of connection.Run. Those are minor. The major issue is that the Connection constructor is incorrect. It took me time to figure out what the correct way is to call the constructor. So now to the solution of my version of the code. Unfortunately with async/await it is not as easy as simply adding "await". Intellisense complains as soon as I add await; it says that Main must be async. That is why I did the work in a separate function so that it can be async. However adding .Wait() seems to solve the problem except now I am getting An error occurred while sending the request. Is the following correct? If it is I don't know what the problem is.
Is that the correct syntax for name? |
Okay the InnerException is:
I found: I do not understand all of those but I changed the target framework version to 4.6 and that error went away. Then the result was null. So I tried using "Repos" for the name instead of SimpleSamples.Repos and that works. |
I installed into a console project using NuGet. I created an OAuth token as in Forming Calls with GraphQL and Creating a personal access token for the command line. The following is my code.
It works up to the call to connection.Run, then quits. It just ends. When I single-step using the debugger it still ends at that line, no diagnostic information or anything.
I apologize if this is a C# problem or a problem resulting from me not reading the documentation well enough. Is it? Or should it at least give me an exception?
The text was updated successfully, but these errors were encountered: