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

cli: support generating generic type parameters #158

Merged
merged 8 commits into from
Oct 26, 2024

Conversation

hgiasac
Copy link
Collaborator

@hgiasac hgiasac commented Oct 22, 2024

Support generating generic type parameters

type GetCustomHeadersArguments[T any, S int | int8 | int16 | int32 | int64] struct {
	Headers map[string]string         `json:"headers"`
	Input   *T                        `json:"input"`
	Other   *GetCustomHeadersOther[S] `json:"other"`
}

type GetCustomHeadersOther[T int | int8 | int16 | int32 | int64] struct {
	Value T `json:"value"`
}

type GetCustomHeadersResult[T any, O int | int8 | int16 | int32 | int64] struct {
	Headers  map[string]string `json:"headers"`
	Response T
	Other    *GetCustomHeadersOther[O] `json:"other"`
}

func FunctionGetCustomHeaders(ctx context.Context, state *types.State, arguments *GetCustomHeadersArguments[BaseAuthor, int]) (GetCustomHeadersResult[HelloResult, int64], error) {
    // ...
}
{
  "collections": [],
  "functions": [
    {
      "arguments": {
        "headers": {
          "type": {
            "name": "JSON",
            "type": "named"
          }
        },
        "input": {
          "type": {
            "type": "nullable",
            "underlying_type": {
              "name": "BaseAuthor",
              "type": "named"
            }
          }
        },
        "other": {
          "type": {
            "type": "nullable",
            "underlying_type": {
              "name": "GetCustomHeadersOther_int",
              "type": "named"
            }
          }
        }
      },
      "name": "getCustomHeaders",
      "result_type": {
        "name": "GetCustomHeadersResult_HelloResult_int64",
        "type": "named"
      }
    }
  ],
  "object_types": {
    "BaseAuthor": {
      "fields": {
        "name": {
          "type": {
            "name": "String",
            "type": "named"
          }
        }
      }
    },
    "GetCustomHeadersOther_int": {
      "fields": {
        "value": {
          "type": {
            "name": "Int32",
            "type": "named"
          }
        }
      }
    },
    "GetCustomHeadersResult_HelloResult_int64": {
      "fields": {
        "Response": {
          "type": {
            "name": "HelloResult",
            "type": "named"
          }
        },
        "headers": {
          "type": {
            "name": "JSON",
            "type": "named"
          }
        },
        "other": {
          "type": {
            "type": "nullable",
            "underlying_type": {
              "name": "GetCustomHeadersOther_int",
              "type": "named"
            }
          }
        }
      }
    },
    "HelloResult": {
      "fields": {
        "error": {
          "type": {
            "type": "nullable",
            "underlying_type": {
              "name": "JSON",
              "type": "named"
            }
          }
        },
        "foo": {
          "type": {
            "name": "Foo",
            "type": "named"
          }
        },
        "id": {
          "type": {
            "name": "UUID",
            "type": "named"
          }
        },
        "num": {
          "type": {
            "name": "Int32",
            "type": "named"
          }
        },
        "text": {
          "type": {
            "name": "String",
            "type": "named"
          }
        }
      }
    }
  }
}

Copy link

github-actions bot commented Oct 22, 2024

Code Coverage

Package Line Rate Health
github.com/hasura/ndc-sdk-go/cmd/hasura-ndc-go/command/internal 82%
github.com/hasura/ndc-sdk-go/cmd/hasura-ndc-go/command 40%
github.com/hasura/ndc-sdk-go/cmd/hasura-ndc-go/version 43%
github.com/hasura/ndc-sdk-go/connector 53%
github.com/hasura/ndc-sdk-go/example/reference 57%
github.com/hasura/ndc-sdk-go/ndctest 51%
github.com/hasura/ndc-sdk-go/scalar 98%
github.com/hasura/ndc-sdk-go/schema 50%
github.com/hasura/ndc-sdk-go/utils 32%
Summary 54% (6022 / 11246)

Minimum allowed line rate is 40%

@hgiasac hgiasac marked this pull request as ready for review October 24, 2024 07:29
@hgiasac hgiasac merged commit c2d70a7 into main Oct 26, 2024
2 checks passed
@hgiasac hgiasac deleted the support-generic-type-parameters branch October 26, 2024 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant