-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
GraphQL API #17903
GraphQL API #17903
Changes from all commits
4b53623
e0f4d7e
c46a697
ed02332
cd53e60
4e3be4f
9286152
4ecd3de
76e45cf
460d158
75aeee1
42bbab1
c6c6a7a
59e2a7f
8790e18
ba6f531
268a03b
21cef58
d92e373
b235d18
549d649
19735c1
135b7d9
0e6fa8e
32068e0
c3387f8
a79bacd
c5f893d
205f82e
844aa56
5719808
532ec8e
c104779
1c5ed0d
84874ac
738f505
202a100
c780558
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,25 @@ func (b Bytes) String() string { | |
return Encode(b) | ||
} | ||
|
||
// ImplementsGraphQLType returns true if Bytes implements the specified GraphQL type. | ||
func (b Bytes) ImplementsGraphQLType(name string) bool { return name == "Bytes" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
|
||
// UnmarshalGraphQL unmarshals the provided GraphQL query data. | ||
func (b *Bytes) UnmarshalGraphQL(input interface{}) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
var err error | ||
switch input := input.(type) { | ||
gballet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case string: | ||
data, err := Decode(input) | ||
if err != nil { | ||
return err | ||
} | ||
*b = data | ||
default: | ||
err = fmt.Errorf("Unexpected type for Bytes: %v", input) | ||
} | ||
return err | ||
} | ||
|
||
// UnmarshalFixedJSON decodes the input as a string with 0x prefix. The length of out | ||
// determines the required input length. This function is commonly used to implement the | ||
// UnmarshalJSON method for fixed-size types. | ||
|
@@ -187,6 +206,25 @@ func (b *Big) String() string { | |
return EncodeBig(b.ToInt()) | ||
} | ||
|
||
// ImplementsGraphQLType returns true if Big implements the provided GraphQL type. | ||
func (b Big) ImplementsGraphQLType(name string) bool { return name == "BigInt" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
|
||
// UnmarshalGraphQL unmarshals the provided GraphQL query data. | ||
func (b *Big) UnmarshalGraphQL(input interface{}) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
var err error | ||
switch input := input.(type) { | ||
gballet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case string: | ||
return b.UnmarshalText([]byte(input)) | ||
case int32: | ||
var num big.Int | ||
num.SetInt64(int64(input)) | ||
*b = Big(num) | ||
default: | ||
err = fmt.Errorf("Unexpected type for BigInt: %v", input) | ||
} | ||
return err | ||
} | ||
|
||
// Uint64 marshals/unmarshals as a JSON string with 0x prefix. | ||
// The zero value marshals as "0x0". | ||
type Uint64 uint64 | ||
|
@@ -234,6 +272,23 @@ func (b Uint64) String() string { | |
return EncodeUint64(uint64(b)) | ||
} | ||
|
||
// ImplementsGraphQLType returns true if Uint64 implements the provided GraphQL type. | ||
func (b Uint64) ImplementsGraphQLType(name string) bool { return name == "Long" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
|
||
// UnmarshalGraphQL unmarshals the provided GraphQL query data. | ||
func (b *Uint64) UnmarshalGraphQL(input interface{}) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
var err error | ||
switch input := input.(type) { | ||
gballet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case string: | ||
return b.UnmarshalText([]byte(input)) | ||
case int32: | ||
*b = Uint64(input) | ||
default: | ||
err = fmt.Errorf("Unexpected type for Long: %v", input) | ||
} | ||
return err | ||
} | ||
|
||
// Uint marshals/unmarshals as a JSON string with 0x prefix. | ||
// The zero value marshals as "0x0". | ||
type Uint uint | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,21 @@ func (h Hash) Value() (driver.Value, error) { | |
return h[:], nil | ||
} | ||
|
||
// ImplementsGraphQLType returns true if Hash implements the specified GraphQL type. | ||
func (_ Hash) ImplementsGraphQLType(name string) bool { return name == "Bytes32" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
|
||
// UnmarshalGraphQL unmarshals the provided GraphQL query data. | ||
func (h *Hash) UnmarshalGraphQL(input interface{}) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
var err error | ||
switch input := input.(type) { | ||
gballet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case string: | ||
*h = HexToHash(input) | ||
default: | ||
err = fmt.Errorf("Unexpected type for Bytes32: %v", input) | ||
} | ||
return err | ||
} | ||
|
||
// UnprefixedHash allows marshaling a Hash without 0x prefix. | ||
type UnprefixedHash Hash | ||
|
||
|
@@ -268,6 +283,21 @@ func (a Address) Value() (driver.Value, error) { | |
return a[:], nil | ||
} | ||
|
||
// ImplementsGraphQLType returns true if Hash implements the specified GraphQL type. | ||
func (a Address) ImplementsGraphQLType(name string) bool { return name == "Address" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
|
||
// UnmarshalGraphQL unmarshals the provided GraphQL query data. | ||
func (a *Address) UnmarshalGraphQL(input interface{}) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a public method. Please add a method doc for it. |
||
var err error | ||
switch input := input.(type) { | ||
gballet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case string: | ||
*a = HexToAddress(input) | ||
default: | ||
err = fmt.Errorf("Unexpected type for Address: %v", input) | ||
} | ||
return err | ||
} | ||
|
||
// UnprefixedAddress allows marshaling an Address without 0x prefix. | ||
type UnprefixedAddress Address | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been working on reformatting the flags a bit for a while now, making them more namespace-y. E.g.
Please use the same format for any new flag:
graphql.addr
,graphql.port
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, instead of piggiebacking on RPCCors and RPCVhosts, please define a separate set. Since we're talking about two different TCP endpoints, it's imho necessary to be able to configure them separately.