Skip to content
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

Cannot retrieve IGitObject which is a Union in correct object type #195

Open
hanzworld opened this issue Mar 21, 2019 · 2 comments
Open
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@hanzworld
Copy link

hanzworld commented Mar 21, 2019

Summary

Depending how a GitHub Release is created, a Release.Tag.Target can either refer to a Commit object or to a Tag object. To retrieve the target Sha1 of the Release, inline fragments are required in a GraphQL query.

It doesn't currently seem possible to reproduce this using the Octokit.GraphQL library as the Switch<> syntax is not available on Target's object type (which is IGitObject), nor on it's parent Tag's object type (which is Ref ... just in case there was syntactic sugar going on somewhere).

Relevant information

Here's some GraphQL that reproduces this:

query releases {
  repository(owner:"MyOrg", name:"MyRepo") {
    releases(
      first:2
      orderBy:{field: CREATED_AT, direction:DESC}){
        nodes{        
      	name
        createdAt,
        publishedAt
        tag{
          name
          target{
            ... on Commit{
              oid
              }
          }
          target {            
            ... on Tag {
              target {
		... on Commit {
                  oid
                }
              }
            }
          }
        }    
      }
    }    
  }  
}

Please note that I am unable to provide you with a public example of this in the real world as I'm using GitHub Enterprise. However here is a (redacted) version of the results when this is run against my server:

{
  "data": {
    "repository": {
      "releases": {
        "nodes": [
          {
            "name": "DB-10.222.0.65",
            "createdAt": "2018-10-11T20:58:59Z",
            "publishedAt": "2018-10-11T22:09:32Z",
            "tag": {
              "name": "XDB-10.222.0.65",
              "target": {
                "oid": "1b15628099a241d2d1d345aa112222027e120948"
              }
            }
          },
          {
            "name": "DB-10.221.3.79",
            "createdAt": "2018-10-11T03:51:49Z",
            "publishedAt": "2018-10-11T03:52:39Z",
            "tag": {
              "name": "0.0.95",
              "target": {
                "target": {
                  "oid": "4ea68920cf2d3d4f3771edae512c10f87922c4e7"
                }
              }
            }
          }
        ]
      }
    }
  }
}

Based on your documentation, this is some pseudo code of what I would expect to be able to do:

var query = new Query()
	.Repository(name: "MyOrg", owner: "MyRepo")
	.Releases(first: 2, orderBy: new ReleaseOrder() { Direction = OrderDirection.Desc, Field = ReleaseOrderField.CreatedAt })
	.Nodes
	.Select(release => new 
	{
		CreatedAt = release.CreatedAt,
		Name = release.Name,
		PublishedAt = release.PublishedAt,
		Url = release.Url,
		Sha1 = release.Tag.Target.Select(target => target.Switch<TargetModel>(when =>
			when.Commit(commit => commit.Oid)
			.Tag(tag => tag.Target.Cast<Commit>().Oid)
	});

I've had a look through the library code and as far as I can tell it's isn't supported. However, feel free to let me know if it's a PEBKAC error!

Thanks for reading.

@jamisonhyatt
Copy link

Well, if you're using the latest nuget package I don't think they have published the commit with the Union Types - looks like the last version was end of October, and union types were merged November.

However, in the code I still don't think they have a Selector on that IGitObject. The same is true of RepositoryOwner, which is an IRepositoryOwner in graphql.net - as far as I can tell you cannot type switch on the owner or organization, and pass the correct concrete type back.

I don't actually see how you would identify what type of owner you got back using this library, outside of guess-and-check users and if it errors, check orgs.

Am I missing something? Is there a simple way of returning __typename that makes all this go away?

@github-actions
Copy link

github-actions bot commented Dec 3, 2022

👋 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 github-actions bot added the Status: Stale Used by stalebot to clean house label Dec 3, 2022
@kfcampbell kfcampbell added Priority: Normal Type: Support Any questions, information, or general needs around the SDK or GitHub APIs labels Dec 5, 2022
@github-actions github-actions bot removed the Status: Stale Used by stalebot to clean house label Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
None yet
Development

No branches or pull requests

4 participants