Authentication-Results: mail-b.sr.ht; dkim=pass header.d=emersion.fr header.i=@emersion.fr Received: from mail-4317.proton.ch (mail-4317.proton.ch [185.70.43.17]) by mail-b.sr.ht (Postfix) with ESMTPS id 94A2F11EF1E for <~emersion/hut-dev@lists.sr.ht>; Sun, 23 Jan 2022 00:19:15 +0000 (UTC) Date: Sun, 23 Jan 2022 00:19:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emersion.fr; s=protonmail2; t=1642897153; bh=V2DVF2PuwCknsqPpRAONTumBwVrJmqviSkUYvWmN6Rg=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc; b=evyKyNtvxnIPCojp9gpz3BwPMQX3KeuZy1933iu8shKVlZDNuJezbU4YGvplkC/qj M78VIkPbMORIoPcu4gkNjci08Ucm8Q07Tu6gutMPW3uzwA/y+KOym7REb8nqMda4nE A81BEyhvLLYnDgLdS9ZhlIZN0hBqs/R4/MZTBDg1fV6tIUx9Q13akDZtgbd65ZKkNS mHm0eC4DBA2Q+CqFnyxF36n/biJz9/8FM+V/I4BcHATWDE9Mbw5YVkjCBcbzKh+ojw jgZDKTcfOVQtWkp/yOmay8u0CAXHYBnTmn+gK8UcxD9EDOftE2vWwVQKAXaPeKcYaT 5KDtOfyG0iYlg== To: Renato Torres From: Simon Ser Cc: ~emersion/hut-dev@lists.sr.ht Reply-To: Simon Ser Subject: Re: [PATCH v1 0/1] git: show license spike Message-ID: In-Reply-To: <20220122233022.1256016-1-renato.torres@protonmail.com> References: <20220122233022.1256016-1-renato.torres@protonmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch On Sunday, January 23rd, 2022 at 00:31, Renato Torres wrote: > This is not a final patch. > > Following one of the comments from Thorben G=C3=BCnther regarding the git > show command, I did a spike to show the license of a repository. > > The command to show the license is: > > go run . git show hut --license > go run . git show hut -l > > If used with the "license" flag the git show command shows only the > license, shipping all the other information. This allows to fetch the > license and use the output to feed other scripts. > > I was able to get the LICENSE contents by defining the query > licenseByRepositoryName. > > I had an issue with this query because the Go structure returned is > an *Object and therefore I could not cast to a TextBlob to get the > contents of the file. > > To make it work I changed manually the gql.go (I know I cannot do it) > to have the Object field be a map[string]interface{} instead of *Object: > > type TreeEntry struct { > =09Id string `json:"id"` > =09Name string `json:"name"` > =09Object map[string]interface{} `json:"object"` // change > =09Mode int32 `json:"mode"` > } > > Questions: > > 1. Is this feature usefull? I wonder. Maybe a more generally useful feature could be a cat-file command= . > 2. Is there a better way to get a file? The current way sounds good. > 3. Should we change gqlclientgen to define a Go interface{} > when the type in the schema.graphqls is an interface? I've been wondering about this, and I'm not sure a Go interface is the best way to represent a GraphQL interface. Go interfaces describe common methods= , here what we want to do is describe common struct fields. Moreover, unless = the user explicitly asks for the special GraphQL "__typename" field, gqlclient = has no way to know the real underlying type of an Object. Maybe instead we can generate a method on Object which takes care of the unwrapping. type Object struct { Name string =E2=80=A6 raw json.RawMessage } func (object *Object) AsTextBlob() (*TextBlob, error) { var textBlob TextBlob err :=3D json.Decode(object.raw, &textBlob) return textBlob, err } Ideally we'd check "__typename" too, and fail on mismatch. Maybe it would b= e a good idea to require the user to request "__typename" for queries containin= g type conditions, to make sure we don't perform any erroneous type conversio= n. Maybe we could just have a single method to unwrap the interface: type Object struct { Name string =E2=80=A6 unwrapped interface{} } func (object *Object) UnmarshalJSON(b []byte) error { // Unmarshal the interface fields =E2=80=A6 // Unmarshal the real underlying type switch typeName { case "TextBlob": var textBlob TextBlob err :=3D json.Decode(object.raw, &textBlob) return textBlob, err default: return nil, fmt.Errorf("unexpected __typename %q", typeName) } } func (object *Object) Unwrap() interface{} { switch object.unwrapped } This would require us to know about all implementations of a GraphQL interf= ace at generation time. It would seem like this is a promise we can make for si= mple cases, but not sure about federated GraphQL schemas and schemas split into multiple files. Would need to do more research. Any other ideas? Ultimately we can always pick a solution and change it later if needed. gqlclient is still in the early stages and we can make breaking changes if deemed necessary.