Sort operations to guarantee a stable order (#156)

Problem: currently when using a wildcard that covers multiple files in `operations:` YAML directive the generator emits functions in a non-stable ordering due to the use of map for storing file names:

https://github.com/Khan/genqlient/blob/e0accbded177db9143314911bacedf61b2cda656/generate/parse.go#L68-L84

Solution: sort the operations before emitting them.
This commit is contained in:
Nikolay Edigaryev
2021-11-26 12:32:03 -08:00
committed by GitHub
parent 2fdbb629be
commit f80df6d4f1
5 changed files with 445 additions and 329 deletions
+298 -298
View File
@@ -3019,31 +3019,6 @@ type simpleQueryResponse struct {
// GetMe returns simpleQueryResponse.Me, and is useful for accessing the field via an interface.
func (v *simpleQueryResponse) GetMe() simpleQueryMeUser { return v.Me }
func simpleQuery(
ctx context.Context,
client graphql.Client,
) (*simpleQueryResponse, error) {
var err error
var retval simpleQueryResponse
err = client.MakeRequest(
ctx,
"simpleQuery",
`
query simpleQuery {
me {
id
name
luckyNumber
}
}
`,
&retval,
nil,
)
return &retval, err
}
func failingQuery(
ctx context.Context,
client graphql.Client,
@@ -3068,64 +3043,6 @@ query failingQuery {
return &retval, err
}
func queryWithVariables(
ctx context.Context,
client graphql.Client,
id string,
) (*queryWithVariablesResponse, error) {
__input := __queryWithVariablesInput{
Id: id,
}
var err error
var retval queryWithVariablesResponse
err = client.MakeRequest(
ctx,
"queryWithVariables",
`
query queryWithVariables ($id: ID!) {
user(id: $id) {
id
name
luckyNumber
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithOmitempty(
ctx context.Context,
client graphql.Client,
id string,
) (*queryWithOmitemptyResponse, error) {
__input := __queryWithOmitemptyInput{
Id: id,
}
var err error
var retval queryWithOmitemptyResponse
err = client.MakeRequest(
ctx,
"queryWithOmitempty",
`
query queryWithOmitempty ($id: ID) {
user(id: $id) {
id
name
luckyNumber
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithCustomMarshal(
ctx context.Context,
client graphql.Client,
@@ -3155,35 +3072,6 @@ query queryWithCustomMarshal ($date: Date!) {
return &retval, err
}
func queryWithCustomMarshalSlice(
ctx context.Context,
client graphql.Client,
dates []time.Time,
) (*queryWithCustomMarshalSliceResponse, error) {
__input := __queryWithCustomMarshalSliceInput{
Dates: dates,
}
var err error
var retval queryWithCustomMarshalSliceResponse
err = client.MakeRequest(
ctx,
"queryWithCustomMarshalSlice",
`
query queryWithCustomMarshalSlice ($dates: [Date!]!) {
usersBornOnDates(dates: $dates) {
id
name
birthdate
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithCustomMarshalOptional(
ctx context.Context,
client graphql.Client,
@@ -3215,202 +3103,26 @@ query queryWithCustomMarshalOptional ($date: Date, $id: ID) {
return &retval, err
}
func queryWithInterfaceNoFragments(
func queryWithCustomMarshalSlice(
ctx context.Context,
client graphql.Client,
id string,
) (*queryWithInterfaceNoFragmentsResponse, error) {
__input := __queryWithInterfaceNoFragmentsInput{
Id: id,
dates []time.Time,
) (*queryWithCustomMarshalSliceResponse, error) {
__input := __queryWithCustomMarshalSliceInput{
Dates: dates,
}
var err error
var retval queryWithInterfaceNoFragmentsResponse
var retval queryWithCustomMarshalSliceResponse
err = client.MakeRequest(
ctx,
"queryWithInterfaceNoFragments",
"queryWithCustomMarshalSlice",
`
query queryWithInterfaceNoFragments ($id: ID!) {
being(id: $id) {
__typename
query queryWithCustomMarshalSlice ($dates: [Date!]!) {
usersBornOnDates(dates: $dates) {
id
name
}
me {
id
name
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithInterfaceListField(
ctx context.Context,
client graphql.Client,
ids []string,
) (*queryWithInterfaceListFieldResponse, error) {
__input := __queryWithInterfaceListFieldInput{
Ids: ids,
}
var err error
var retval queryWithInterfaceListFieldResponse
err = client.MakeRequest(
ctx,
"queryWithInterfaceListField",
`
query queryWithInterfaceListField ($ids: [ID!]!) {
beings(ids: $ids) {
__typename
id
name
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithInterfaceListPointerField(
ctx context.Context,
client graphql.Client,
ids []string,
) (*queryWithInterfaceListPointerFieldResponse, error) {
__input := __queryWithInterfaceListPointerFieldInput{
Ids: ids,
}
var err error
var retval queryWithInterfaceListPointerFieldResponse
err = client.MakeRequest(
ctx,
"queryWithInterfaceListPointerField",
`
query queryWithInterfaceListPointerField ($ids: [ID!]!) {
beings(ids: $ids) {
__typename
id
name
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithFragments(
ctx context.Context,
client graphql.Client,
ids []string,
) (*queryWithFragmentsResponse, error) {
__input := __queryWithFragmentsInput{
Ids: ids,
}
var err error
var retval queryWithFragmentsResponse
err = client.MakeRequest(
ctx,
"queryWithFragments",
`
query queryWithFragments ($ids: [ID!]!) {
beings(ids: $ids) {
__typename
id
... on Being {
id
name
}
... on Animal {
id
hair {
hasHair
}
species
owner {
__typename
id
... on Being {
name
}
... on User {
luckyNumber
}
}
}
... on Lucky {
luckyNumber
}
... on User {
hair {
color
}
}
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithNamedFragments(
ctx context.Context,
client graphql.Client,
ids []string,
) (*queryWithNamedFragmentsResponse, error) {
__input := __queryWithNamedFragmentsInput{
Ids: ids,
}
var err error
var retval queryWithNamedFragmentsResponse
err = client.MakeRequest(
ctx,
"queryWithNamedFragments",
`
query queryWithNamedFragments ($ids: [ID!]!) {
beings(ids: $ids) {
__typename
id
... AnimalFields
... UserFields
}
}
fragment AnimalFields on Animal {
id
hair {
hasHair
}
owner {
__typename
id
... UserFields
... LuckyFields
}
}
fragment UserFields on User {
id
... LuckyFields
... MoreUserFields
}
fragment LuckyFields on Lucky {
... MoreUserFields
luckyNumber
}
fragment MoreUserFields on User {
id
hair {
color
birthdate
}
}
`,
@@ -3482,3 +3194,291 @@ fragment FriendsFields on User {
)
return &retval, err
}
func queryWithFragments(
ctx context.Context,
client graphql.Client,
ids []string,
) (*queryWithFragmentsResponse, error) {
__input := __queryWithFragmentsInput{
Ids: ids,
}
var err error
var retval queryWithFragmentsResponse
err = client.MakeRequest(
ctx,
"queryWithFragments",
`
query queryWithFragments ($ids: [ID!]!) {
beings(ids: $ids) {
__typename
id
... on Being {
id
name
}
... on Animal {
id
hair {
hasHair
}
species
owner {
__typename
id
... on Being {
name
}
... on User {
luckyNumber
}
}
}
... on Lucky {
luckyNumber
}
... on User {
hair {
color
}
}
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithInterfaceListField(
ctx context.Context,
client graphql.Client,
ids []string,
) (*queryWithInterfaceListFieldResponse, error) {
__input := __queryWithInterfaceListFieldInput{
Ids: ids,
}
var err error
var retval queryWithInterfaceListFieldResponse
err = client.MakeRequest(
ctx,
"queryWithInterfaceListField",
`
query queryWithInterfaceListField ($ids: [ID!]!) {
beings(ids: $ids) {
__typename
id
name
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithInterfaceListPointerField(
ctx context.Context,
client graphql.Client,
ids []string,
) (*queryWithInterfaceListPointerFieldResponse, error) {
__input := __queryWithInterfaceListPointerFieldInput{
Ids: ids,
}
var err error
var retval queryWithInterfaceListPointerFieldResponse
err = client.MakeRequest(
ctx,
"queryWithInterfaceListPointerField",
`
query queryWithInterfaceListPointerField ($ids: [ID!]!) {
beings(ids: $ids) {
__typename
id
name
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithInterfaceNoFragments(
ctx context.Context,
client graphql.Client,
id string,
) (*queryWithInterfaceNoFragmentsResponse, error) {
__input := __queryWithInterfaceNoFragmentsInput{
Id: id,
}
var err error
var retval queryWithInterfaceNoFragmentsResponse
err = client.MakeRequest(
ctx,
"queryWithInterfaceNoFragments",
`
query queryWithInterfaceNoFragments ($id: ID!) {
being(id: $id) {
__typename
id
name
}
me {
id
name
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithNamedFragments(
ctx context.Context,
client graphql.Client,
ids []string,
) (*queryWithNamedFragmentsResponse, error) {
__input := __queryWithNamedFragmentsInput{
Ids: ids,
}
var err error
var retval queryWithNamedFragmentsResponse
err = client.MakeRequest(
ctx,
"queryWithNamedFragments",
`
query queryWithNamedFragments ($ids: [ID!]!) {
beings(ids: $ids) {
__typename
id
... AnimalFields
... UserFields
}
}
fragment AnimalFields on Animal {
id
hair {
hasHair
}
owner {
__typename
id
... UserFields
... LuckyFields
}
}
fragment UserFields on User {
id
... LuckyFields
... MoreUserFields
}
fragment LuckyFields on Lucky {
... MoreUserFields
luckyNumber
}
fragment MoreUserFields on User {
id
hair {
color
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithOmitempty(
ctx context.Context,
client graphql.Client,
id string,
) (*queryWithOmitemptyResponse, error) {
__input := __queryWithOmitemptyInput{
Id: id,
}
var err error
var retval queryWithOmitemptyResponse
err = client.MakeRequest(
ctx,
"queryWithOmitempty",
`
query queryWithOmitempty ($id: ID) {
user(id: $id) {
id
name
luckyNumber
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func queryWithVariables(
ctx context.Context,
client graphql.Client,
id string,
) (*queryWithVariablesResponse, error) {
__input := __queryWithVariablesInput{
Id: id,
}
var err error
var retval queryWithVariablesResponse
err = client.MakeRequest(
ctx,
"queryWithVariables",
`
query queryWithVariables ($id: ID!) {
user(id: $id) {
id
name
luckyNumber
}
}
`,
&retval,
&__input,
)
return &retval, err
}
func simpleQuery(
ctx context.Context,
client graphql.Client,
) (*simpleQueryResponse, error) {
var err error
var retval simpleQueryResponse
err = client.MakeRequest(
ctx,
"simpleQuery",
`
query simpleQuery {
me {
id
name
luckyNumber
}
}
`,
&retval,
nil,
)
return &retval, err
}
+117
View File
@@ -1560,6 +1560,41 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql
return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res)
}
func (ec *executionContext) ___Directive_isRepeatable(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
fc := &graphql.FieldContext{
Object: "__Directive",
Field: field,
Args: nil,
IsMethod: false,
IsResolver: false,
}
ctx = graphql.WithFieldContext(ctx, fc)
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.IsRepeatable, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(bool)
fc.Result = res
return ec.marshalNBoolean2bool(ctx, field.Selections, res)
}
func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
@@ -2858,6 +2893,11 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS
if out.Values[i] == graphql.Null {
invalids++
}
case "isRepeatable":
out.Values[i] = ec.___Directive_isRepeatable(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
default:
panic("unknown field " + strconv.Quote(field.Name))
}
@@ -3109,6 +3149,7 @@ func (ec *executionContext) marshalNBeing2ᚕgithubᚗcomᚋKhanᚋgenqlientᚋi
}
wg.Wait()
return ret
}
@@ -3169,6 +3210,12 @@ func (ec *executionContext) marshalNDate2ᚕstringᚄ(ctx context.Context, sel a
ret[i] = ec.marshalNDate2string(ctx, sel, v[i])
}
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3214,6 +3261,12 @@ func (ec *executionContext) marshalNID2ᚕstringᚄ(ctx context.Context, sel ast
ret[i] = ec.marshalNID2string(ctx, sel, v[i])
}
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3291,6 +3344,13 @@ func (ec *executionContext) marshalNUser2ᚕᚖgithubᚗcomᚋKhanᚋgenqlient
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3342,6 +3402,13 @@ func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgq
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3415,6 +3482,13 @@ func (ec *executionContext) marshalN__DirectiveLocation2ᚕstringᚄ(ctx context
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3464,6 +3538,13 @@ func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋg
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3505,6 +3586,13 @@ func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgen
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3691,6 +3779,7 @@ func (ec *executionContext) marshalOUser2ᚕᚖgithubᚗcomᚋKhanᚋgenqlient
}
wg.Wait()
return ret
}
@@ -3738,6 +3827,13 @@ func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgq
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3778,6 +3874,13 @@ func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgen
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3818,6 +3921,13 @@ func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋg
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@@ -3865,6 +3975,13 @@ func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgen
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}