Skip to content

Commit

Permalink
fix: interface module bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Niraj-Kamdar committed Sep 8, 2022
1 parent 0e8347b commit 437f3c1
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use {{crate}}::{{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeywor
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {}

{{^isInterface}}
impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
pub const URI: &'static str = "{{uri}}";
Expand All @@ -51,3 +52,30 @@ impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
{{/last}}
{{/methods}}
}
{{/isInterface}}
{{#isInterface}}
impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
pub const INTERFACE_URI: &'static str = "{{uri}}";
pub uri: String;
pub fn new(uri: String) -> {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
{{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {uri: uri}
}

{{#methods}}
pub fn {{#toLower}}{{name}}{{/toLower}}(&self, args: &Args{{#toUpper}}{{name}}{{/toUpper}}) -> Result<{{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, String> {
let uri = self.uri;
let args = serialize_{{#toLower}}{{name}}{{/toLower}}_args(args).map_err(|e| e.to_string())?;
let result = subinvoke::wrap_subinvoke(
uri,
"{{name}}",
args,
)?;
deserialize_{{#toLower}}{{name}}{{/toLower}}_result(result.as_slice()).map_err(|e| e.to_string())
}
{{^last}}

{{/last}}
{{/methods}}
}
{{/isInterface}}

0 comments on commit 437f3c1

Please sign in to comment.