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

Cannot compile issue queries from documentation

Open duncanawoods opened this issue 5 years ago • 4 comments

I am using

  • .net core 3.0
  • Octokit.GraphQl 0.1.40beta

I am trying to run the issue queries from the documentation but can't get them to build.

Am I missing something?

using System.Collections.Generic;
using Octokit.GraphQL;

namespace OctoSamples
{
    public class SampleCode
    {
        class RepositoryModel
        {
            public string Name { get; set; }
            public string Description { get; set; }
            public List<IssueModel> Issues { get; set; }
        }
        
        class IssueModel
        {
            public int Number { get;set; }
            public string Title { get; set; }
        }
        
        public static void Hmm()
        {
            // https://github.com/octokit/octokit.graphql.net/blob/master/docs/writing-queries.md
            //
            // # Nested Queries

            var query = new Query()
                .Repository("octokit", "octokit.net")
                .Select(r => new
                {
                    r.Name,
                    r.Description,
                    Issues = r.Issues(100, null, null, null, null, null, null).Select(i => new
                    {
                        i.Number,
                        i.Title,
                    }).ToList(),
                });
            
            // https://github.com/octokit/octokit.graphql.net/blob/master/docs/writing-queries.md
            //
            // # Selecting into Named Classes
            
            var query2 = new Query()
                .Repository("octokit", "octokit.net")
                .Select(r => new RepositoryModel
                {
                    r.Name,
                    r.Description,
                    Issues = r.Issues(100, null, null, null, null, null, null).Select(i => new IssueModel
                    {
                        i.Number,
                        i.Title,
                    }).ToList(),
                });
        }
    }
}
0>Samples.cs(35,27): Error CS1061 : 'IssueConnection' does not contain a definition for 'Number' and no accessible extension method 'Number' accepting a first argument of type 'IssueConnection' could be found (are you missing a using directive or an assembly reference?)
0>Samples.cs(36,27): Error CS1061 : 'IssueConnection' does not contain a definition for 'Title' and no accessible extension method 'Title' accepting a first argument of type 'IssueConnection' could be found (are you missing a using directive or an assembly reference?)
0>Samples.cs(48,21): Error CS0747 : Invalid initializer member declarator
0>Samples.cs(49,21): Error CS0747 : Invalid initializer member declarator
0>Samples.cs(51,21): Error CS1922 : Cannot initialize type 'SampleCode.IssueModel' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
0>Samples.cs(52,27): Error CS1061 : 'IssueConnection' does not contain a definition for 'Number' and no accessible extension method 'Number' accepting a first argument of type 'IssueConnection' could be found (are you missing a using directive or an assembly reference?)
0>Samples.cs(53,27): Error CS1061 : 'IssueConnection' does not contain a definition for 'Title' and no accessible extension method 'Title' accepting a first argument of type 'IssueConnection' could be found (are you missing a using directive or an assembly reference?)

duncanawoods avatar Dec 17 '19 11:12 duncanawoods

I just had the same problem, the sample should be:

            var query = new Query()
                .Repository("octokit", "octokit.net")
                .Select(r => new
                {
                    r.Name,
                    r.Description,
                    Issues = r.Issues(100, null, null, null, null, null, null)
                        .Nodes
                        .Select(i => new
                        {
                            i.Number,
                            i.Title,
                        }).ToList(),
                });

So .Select(i => new turns into .Nodes.Select(i => new.

nul800sebastiaan avatar Feb 14 '21 10:02 nul800sebastiaan

@nul800sebastiaan in the current version you need one more "null" in issues:

            var query = new Query()
                .Repository("octokit", "octokit.net")
                .Select(r => new
                {
                    r.Name,
                    r.Description,
                    Issues = r.Issues(100, null, null, null, null, null, null, null)
                        .Nodes
                        .Select(i => new
                        {
                            i.Number,
                            i.Title,
                        }).ToList(),
                });

p-bojkowski avatar Apr 10 '21 08:04 p-bojkowski

Or get all issues with one call without paging:

var query = new Query()
	.Repository("octokit", "octokit.net")
	.Issues()
	.AllPages() // Auto-pages Issues
	.Select(issue => new
	{
		issue.Title,
		issue.Id
	}).Compile();

p-bojkowski avatar Apr 10 '21 09:04 p-bojkowski

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

github-actions[bot] avatar Dec 03 '22 01:12 github-actions[bot]