Add descriptions / comments to graphql arguments? - ruby

Is it possible to add a description or a comment to the arguments that are accepted in a query with graphql?
I have a Query as follows:
field :users, types[Types::UserType] do
description 'List of Users. Date parameters accepted in yyyy/mm/dd format.'
# Required for date range search, accepts string (yyyy/mm/dd)
argument :from_date, types.String, default_value: nil
as you can see, currently I'm adding the description of the parameters to the description of the field. In the graphiql schema where it describes the types I see:
users(from_date: Stringto_date: Stringemail: Stringname: Stringoffset: Intlimit: Int): [UserType]
when I click on the from_date it describes a string. Is there anyway to have it describe the format of the string? eg. "A string in yyyy/mm/dd format."
Thanks!

Looking at the docs, you should be able to do something like:
argument :favoriteFood, types.String, "A string in yyyy/mm/dd format", default_value: nil

Related

Can you alias a basic type like String in GraphQL? like `type Token = String`?

Can you alias a basic type like String in GraphQL? like type Token = String?
Or it has to be a class/struct?
If it's only about name, just leave is as string.
If it's a special kind of string, like Mongo ObjectID, which has rules like string length or checksum, you can create GraphQL scalar for that purpose.

can .proto file fields be without values?

I received "missing field number" error. Is it possible to declare fields without value? since i do not have a default value to the fields.
syntax = "proto3";
package tutorial;
message Person {
required string name;
required string email;
}
The field number is not refer to a default value but each field in the message definition has a unique number. These numbers are used to identify your fields in the message binary format, and should not be changed once your message type is in use.
More info here in the doc

Case Insensitive String parameter in schema of openApi

I have an open API spec with a parameter like this: 
- name: platform
in: query
description: "Platform of the application"
required: true
schema:
type: string
enum:
- "desktop"
- "online"
when I get the "platform" parameter from URL , it can be like this :
platform=online or 
platform=ONLINE or 
platform=Online or 
platform=onLine  or ... any other format
but when I am going to use it , it is only valid if the parameter is all lower case like "platform=online", obviously to match the enum value.
how can I make schema to be the case insensitive and understand all types of passed parameters?
Enums are case-sensitive. To have a case-insensitive schema, you can use a regular expression pattern instead:
- name: platform
in: query
description: 'Platform of the application. Possible values: `desktop` or `online` (case-insensitive)'
required: true
schema:
type: string
pattern: '^[Dd][Ee][Ss][Kk][Tt][Oo][Pp]|[Oo][Nn][Ll][Ii][Nn][Ee]$'
Note that pattern is the pattern itself and does not support JavaScript regex literal syntax (/abc/i), which means you cannot specify flags like i (case insensitive search). As a result you need to specify both uppercase and lowercase letters in the pattern itself.
Alternatively, specify the possible values in the description rather than in pattern/enum, and verify the parameter values on the back end.
Here's the related discussion in the JSON Schema repository (OpenAPI uses JSON Schema to define the data types): Case Insensitive Enums?

Getting the Short/Long Name of the Translate value

I have a Field naming SUBJECT with translate value:
Translate Value: Math
Long Name: Mathematics
Short Name: Mathematics
Now I have a Record naming PS_CLASS which has SUBJECT as field, now basically the values of SUBJECT in PS_CLASS would be 'Math'.
The problem is I want it to store the Long Name of that translate value, so instead of SUBJECT having 'Math' as value, it will have the value of 'Mathematics'.
Any idea how to do this?
Thanks!

Validate Date FORMAT (not date string) using MomentJS?

I've seen that you can use an ".isValid()" function to check that a given string is in a date format:
moment('2007-05-05', 'YYYY-MM-DD', true).isValid()
But is there a way to confirm that the format is correct? For example:
'YYYY-MM-DD' should return true, but
'YYYY-MM-DDsadsadl' should return false since the characters at the end of the string aren't valid DateTime chars.
We're working on a tool that allows a user to input an existing date format, and then a second input to enter the desired format, but we need validation to ensure the string can properly parse and convert, but they aren't entering a specific date.
The application must accept any and all possible date formats.
Use the following function to validate your format.
validFormat = function(inputFormat){
var validation = moment(moment('2017-06-17').format(inputFormat), inputFormat).inspect();
if(validation.indexOf('invalid') < 0)
return true;
else
return false;
}
Do spend some time to understand this. This simply does a reverse verification using inspect(). The date 2017-06-17 can be replaced by any valid date.
This Moment Js Docs will help you identify the valid formats.
Just make a call to this function as
validFormat('YYYY MM DD')
const getIsValid = inputFormat => moment(moment().format(inputFormat), inputFormat).isValid()
Explanation:
moment().format(inputFormat) - Create a date string from the current time from that format
This is then wrapped with moment() to make that string a moment date object, defining the format to parse it with. Finally we call the isValid() property on that moment date object. This ensures we are able to both create and parse a moment with our custom format.

Resources