Skip to content

Commit

Permalink
add deprecated notes
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Aug 22, 2024
1 parent 83f7a0a commit f358971
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
58 changes: 44 additions & 14 deletions schema/extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ func (j *ArgumentType) UnmarshalJSON(b []byte) error {

// Argument is provided by reference to a variable or as a literal value
type Argument struct {
Type ArgumentType `json:"type" yaml:"type" mapstructure:"type"`
Name string `json:"name" yaml:"name" mapstructure:"name"`
Value any `json:"value" yaml:"value" mapstructure:"value"`
// Deprecated: may change Argument to a generic map in the future
Type ArgumentType `json:"type" yaml:"type" mapstructure:"type"`
// Deprecated: may change Argument to a generic map in the future
Name string `json:"name" yaml:"name" mapstructure:"name"`
// Deprecated: may change Argument to a generic map in the future
Value any `json:"value" yaml:"value" mapstructure:"value"`
}

// ArgumentEncoder abstracts the interface for Argument
Expand Down Expand Up @@ -119,6 +122,30 @@ func (j *Argument) UnmarshalJSON(b []byte) error {
return nil
}

// NewLiteralArgument creates an argument with a literal value
//
// Deprecated: use [NewArgumentLiteral] instead
//
// [NewArgumentLiteral]: https://pkg.go.dev/github.com/hasura/ndc-sdk-go/schema#NewArgumentLiteral
func NewLiteralArgument(value any) *Argument {
return &Argument{
Type: ArgumentTypeLiteral,
Value: value,
}
}

// NewVariableArgument creates an argument with a variable name
//
// Deprecated: use [NewArgumentVariable] instead
//
// [NewArgumentVariable]: https://pkg.go.dev/github.com/hasura/ndc-sdk-go/schema#NewArgumentVariable
func NewVariableArgument(name string) *Argument {
return &Argument{
Type: ArgumentTypeVariable,
Name: name,
}
}

// AsLiteral converts the instance to ArgumentLiteral
func (j Argument) AsLiteral() (*ArgumentLiteral, error) {
if j.Type != ArgumentTypeLiteral {
Expand Down Expand Up @@ -165,8 +192,8 @@ type ArgumentLiteral struct {
Value any `json:"value" yaml:"value" mapstructure:"value"`
}

// NewLiteralArgument creates an argument with a literal value
func NewLiteralArgument(value any) *ArgumentLiteral {
// NewArgumentLiteral creates an argument with a literal value
func NewArgumentLiteral(value any) *ArgumentLiteral {
return &ArgumentLiteral{
Type: ArgumentTypeLiteral,
Value: value,
Expand All @@ -187,8 +214,8 @@ type ArgumentVariable struct {
Name string `json:"name" yaml:"name" mapstructure:"name"`
}

// NewVariableArgument creates an argument with a variable name
func NewVariableArgument(name string) *ArgumentVariable {
// NewArgumentVariable creates an argument with a variable name
func NewArgumentVariable(name string) *ArgumentVariable {
return &ArgumentVariable{
Type: ArgumentTypeVariable,
Name: name,
Expand Down Expand Up @@ -250,9 +277,12 @@ func (j *RelationshipArgumentType) UnmarshalJSON(b []byte) error {

// RelationshipArgument is provided by reference to a variable or as a literal value
type RelationshipArgument struct {
Type RelationshipArgumentType `json:"type" yaml:"type" mapstructure:"type"`
Name string `json:"name" yaml:"name" mapstructure:"name"`
Value any `json:"value" yaml:"value" mapstructure:"value"`
// Deprecated: may change RelationshipArgument to a generic map in the future
Type RelationshipArgumentType `json:"type" yaml:"type" mapstructure:"type"`
// Deprecated: may change RelationshipArgument to a generic map in the future
Name string `json:"name" yaml:"name" mapstructure:"name"`
// Deprecated: may change RelationshipArgument to a generic map in the future
Value any `json:"value" yaml:"value" mapstructure:"value"`
}

// RelationshipArgumentEncoder abstracts the interface for RelationshipArgument
Expand Down Expand Up @@ -382,8 +412,8 @@ type RelationshipArgumentColumn struct {
}

// NewRelationshipArgumentColumn creates a RelationshipArgumentColumn instance
func NewRelationshipArgumentColumn(name string) *RelationshipArgument {
return &RelationshipArgument{
func NewRelationshipArgumentColumn(name string) *RelationshipArgumentColumn {
return &RelationshipArgumentColumn{
Type: RelationshipArgumentTypeLiteral,
Name: name,
}
Expand All @@ -404,8 +434,8 @@ type RelationshipArgumentVariable struct {
}

// NewRelationshipArgumentVariable creates a RelationshipArgumentVariable instance
func NewRelationshipArgumentVariable(name string) *RelationshipArgument {
return &RelationshipArgument{
func NewRelationshipArgumentVariable(name string) *RelationshipArgumentVariable {
return &RelationshipArgumentVariable{
Type: RelationshipArgumentTypeVariable,
Name: name,
}
Expand Down
4 changes: 2 additions & 2 deletions schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestQueryRequest(t *testing.T) {
"location": NewColumnField("location", NewNestedObject(map[string]FieldEncoder{
"city": NewColumnField("city", nil),
"campuses": NewColumnFieldWithArguments("campuses", nil, map[string]Argument{
"limit": NewLiteralArgument(nil).Encode(),
"limit": NewArgumentLiteral(nil).Encode(),
}),
})).Encode(),
},
Expand Down Expand Up @@ -544,7 +544,7 @@ func TestQueryRequest(t *testing.T) {
"id": NewColumnField("id", nil).Encode(),
"name": NewColumnField("name", nil).Encode(),
"staff": NewColumnFieldWithArguments("staff", nil, map[string]Argument{
"limit": NewLiteralArgument(nil).Encode(),
"limit": NewArgumentLiteral(nil).Encode(),
}).Encode(),
},
Predicate: NewExpressionExists(
Expand Down

0 comments on commit f358971

Please sign in to comment.