return base64 string from graphql api in rails - ruby-on-rails

I have a graphql api and I want to return a pdf file.
In the first step, I will need to define the query. For that query will a string type returned value can work?
field :pdf, String

Returning a PDF file as a String could work, if encoded as Base64.
This pdf field would be defined in your schema as a nullable String,
e.g. in your own custom type:
type YourType {
pdf: String
}
or as a nullable String-based return value of your own GraphQL query:
Query {
yourQuery(someParam: String!): String
}
Be aware of providing a serverside query/field resolver (a custom data fetcher),
that takes your PDF file, creates a Base64-encoded String of it and returns that String.
On your frontend, this encoded String obviously needs to be decoded again...

Related

Avro IDL generate one schema file with multiple records

I am currently using Avro IDL to generate my classes. However, when generating them a seperate avro schema is generated per record even though they are all nested into one. Is there a way that I can create ONE schema that holds all the records?
protocol CodeQLEvents_v1 {
record InBoundRequestv1 {
string WorkflowId;
string WorkflowInstanceId;
string RepoName;
string OwnerName;
array<string> AdmiralProductId;
}
record Model {
string WorkflowExecutionId;
string ReportId;
string ApplicationId;
}
}

render as JSON not working in Grails

I am fairly new to Groovy and Grails and I am trying to create a method that returns a JSON formatted string.
I read a bit about Converters, and from what I can understand from a couple of sources(here and here) I should be able to do this:
import grails.converters.JSON
class Record {
//...
private Map _metadata = [:]
String getMetadataJSON(){
return render _metadata as JSON
}
}
Not only this does not work, but the "render" keyword is not being resolved.
So my two questions are:
Why is this not working and how should it be done?
What kind of language construct is "render" supposed to be?, a closure?
render is used in a Controller within Grails and not (what appears to be) a Domain Class (in your example). If you want to get a JSON representation of something then simply:
String getMetadataJSON() {
(_metadata as JSON)
}
The above will return a String representation in JSON format. Groovy doesn't require the return keyword.

How to send custom object in httpie request

I am doing a project which uses httpie. I was able to send primitive fields and it's array as a request query parameter. For example, say i have variable named "age" which is integer type, i can send this variable as a Query parameter, Form parameter, or Path parameter. If i want to send the age as a Query parameter, i would write the following:
http -v -f POST 'localhost:8080/api/v1/public/users?age=20'
The problem is when i want to send an object of non-primitive class. For example, i have a class named Name which is following:
public class Name {
String first, middle, last;
}
Now for an object of this class how can i send an object of Name class as a parameter in httpie request. I tried a lot but didn't find any solution.

struts2 - how to expose an action class' field's subclass for conversion to JSON?

class ReportAction{
private Report report;
String reportType;
...
public String execute(){
switch (reportType){
case "user" : someService.getUserReport();
....
}
}
}
Now, the service returns subclasses of Report, depending upon the type of reports asked. When I use the json result type, and specify 'report' to be converted to JSON, I assume that only the fields declared in Report will be converted to JSON, not the fields of the actual subclass reference that 'report' holds. Each subclass of Report has extra fields, and I want them to be included when the 'report' field is converted to JSON

How to control the serialization of types in RouteValueDictionary?

I have code that builds Urls in ASP.NET MVC3 using a RouteValueDictionary and UrlHelper. The problem that I am running into is that MVC calls ToString() on the types in the dictionary. For a particular type I am using, this is not the value that I want to be in the Uri. I cannot change the ToString implementation.
I understand how to create a ModelBinder to handle the deserialization from the Uri, but not the serialization part. How and what do I register in order to control how a type is converted to the Uri parameter?
Thanks,
Erick
For a particular type I am using, this is not the value that I want to be in the Uri
Then don't use this type. Pass the value that you want directly as string in the dictionary:
rvd["key"] = "the value you want";
instead of:
rvd["key"] = new SomeType { Foo = "foo", Bar = "bar" };
The conversion between your type and its string representation should be handled elsewhere.

Resources