Graphene Django disable suggestions "Did you mean ..." - graphql

When you post an query with syntax errors graphql/graphene makes suggestions to you. By example, sending "i", it suggest "ID".
query{
users{
i
}
}
{
"errors": [
{
"message": "Cannot query field \"i\" on type \"User\". Did you mean \"id\"?",
"locations": [
{
"line": 5,
"column": 9
}
]
}
]
}
Can suggestions be disabled?
More info:
Syntax analysis who add suggestions is executed before the middlewares.
Apparently suggestions are made by ScalarLeafsRule class.

Ok, people in graphql-core github repo is awesome, they helped to me to solve this.
So graphql-core has two relevant versions, 3 (current) and 2.3.2 (legacy).
For graphql-core 3, quoting to Cito
Ok, if you want to keep it closed and also disable introspection it makes a little more sense. I suggest you simply set graphql.pyutils.did_you_mean.MAX_LENGTH = 0. I just commited a small change ffdf1b3 that makes this work a bit better.
You can also ask over at https://github.com/graphql/graphql-js/issues if they want to add some functionality to support your use case. From there it would be ported back here.
For legacy version:
from graphql.validation import rules
def get_empty_suggested_field_names(schema, graphql_type, field_name):
return []
def get_empty_suggested_type_names(schema, output_type, field_name):
return []
rules.fields_on_correct_type.get_suggested_field_names = get_empty_suggested_field_names
rules.fields_on_correct_type.get_suggested_type_names = get_empty_suggested_type_n
You can place it on django settings file.
Please follow all the thread on https://github.com/graphql-python/graphql-core/issues/97

Related

Ruby Airbone array testing is not working as expected

I have the json below
{
"menu": {
"sections": [
{
"type": 4,
"frames": [
{
"itens": []
}
],
"order": 0
},
{
"type": 4,
"frames": [
{
"itens": [
{
"id": "1719016",
"type": 0,
"free": false
}
]
}
],
"order": 1
}
]
}
}
and the test below that may check if all json itens in array itens has an ID property:
expect_json_keys('menu.sections.0.frames.*.itens.*', :id)
The problem is that this test runs fine. But should fail.
My test only fail when I change my expectations to that:
expect_json_keys('menu.sections.0.frames.*.itens.0', :id)
Why this test is succesful instead of fail when using itens.*
I reproduced your problem and tried to debug a bit.
I see this airborne gem for the first time (so take the following with a grain of salt), but I think the problem hides in the airborne implementation itself, here, to be more precise: https://github.com/brooklynDev/airborne/blob/master/lib/airborne/path_matcher.rb#L82
This line is intended to run expectation block (this one in this particular case) for each item matching the wildcarded segment, but for an empty array it simply does nothing. No expectations run - no failures.
So it's not something wrong in your tests code, it's about the gem itself.
As a kind of workaround, you could try smth. like the following:
expect_json_types('menu.sections.0.frames.*.itens', :array_of_objects) # <= add this
expect_json_keys('menu.sections.0.frames.*.itens.*', :id)
e.g. testing the type of the value before testing the value itself - in this case it fails with Expected array_of_objects got Array instead
Thank you very much #konstantin-strukov. This solution works fine for this test case.
But in some test cases I still have to write some extra code.
The expectation you´ve writen fails for this json http://www.mocky.io/v2/5c827f26310000e8421d1e83. OK, I have a test case where it should really fail. I´ll use your solution in a lot of use cases. Thank you again.
But I have some test cases that shouldn´t fail if I have at least one filled itens property (http://www.mocky.io/v2/5c827f26310000e8421d1e83). expect_json_keys('menu.sections.0.frames.*.itens.?', :id) should be sufficient but it doesn´t because it works using itens.* or itens.?. I´ve tried to fit your solution in these test cases but it didn´t work as expected.

New Teams Who Bot Actionable Messages Syntax? Undocumented O365ConnectorCard functionality?

I'm working with the O365ConnectorCard capabilities in Teams for bots and I'm trying to recreate the scrolling list of people the new Who bot can produce when you say something like who works with jim#contoso.com?.
You can see what it looks like here.
If it is using the connector card functionality, I'm assuming that is a Section but maybe using undocumented syntax? Additionally, the sections are clickable from the Who bot, but no matter what combination of PotentialAction added, I cannot get the row to have a hover and click of type imBack.
The MessageCard Playground as well doesn't have any examples that match what that Who bot can produce.
Anyone know how this was done? Any MS folks want to post some sample JSON of what's possible but not available yet from the Microsoft.Bot.Connector.Teams NuGet package :)? I'm currently up to v0.8.0.
Thanks!
I believe the Who bot is using the List Layout. The list layout is used to display a collection of cards in a stacked list.
We haven't documented these new card formats yet - we were waiting for Who bot to ship, but there are actually two new card formats, PersonCard and ListCard. You can see some commented-out examples of how to use them here: https://github.com/OfficeDev/BotBuilder-MicrosoftTeams/blob/3c6f07b7600bb20713626cbf79acf5e114e57d0d/CSharp/Tests/Microsoft.Bot.Connector.Teams.Tests.Shared/CardTests.cs.
ListCard is different from List, and there are supports for three kinds of objects in a list: Person, File, and a generic one called "resultitem" - that latter one may not render properly on Android. There's also a way to add a separator line.
This may or may not be enough to get you going, but in case you find it useful:
{
"content":{
"title":"Test List Card",
"items":[
{
"type":"section",
"title":"List Card section"
},
{
"type":"person",
"id":"shmayura#microsoft.com",
"title":"Shanmathi Mayuram Krithivasan",
"subtitle":"SOFTWARE ENGINEER",
"tap":{
"type":"invoke",
"title":"Details?",
"value":"{\"intentName\":\"WhoIs\",\"employeeName\":null,\"employeeEmail\":\"shmayura#microsoft.com\",\"topic\":null}"
}
},
{
"type":"file",
"id":"https://microsoft.sharepoint.com/teams/skypespacesteamnew/Shared%20Documents/Design/FinancialReport.xlsx",
"title":"FinancialReport",
"subtitle":"teams > skypespacesteamnew > design",
"tap":{
"type":"openUrl",
"title":"Open url",
"value":"https://microsoft.sharepoint.com/teams/skypespacesteamnew/Shared%20Documents/Design/FinancialReport.xlsx"
}
},
{
"type":"resultItem",
"title":"Seattle to Chicago",
"subtitle":"$500 July 4 - July 8",
"icon":"https://skypeteamsbotstorage.blob.core.windows.net/bottestartifacts/sandwich_thumbnail.png",
"tap":{
"type":"imBack",
"title":"Reply",
"value":"flightto Chicago"
}
}
],
"buttons":[
{
"type":"imBack",
"title":"Open Online",
"value":"editOnline"
}
]
},
"contentType":"application/vnd.microsoft.teams.card.list"
}

zingchart setseriesdata visibility issue

Pretty straight forward question, as soon as i use setseries data the visibility my pie chart is no longer visible. I have checked the plot object and the series were updated correctly, however since I do not find a visibility attribute anywhere in the plot object, i am at a loss.
The lack of zingcharts documentation and proper examples does not aid either. Im fairly certain this is a simple scenario to solve, but I've been unable to do so.
zingchart.exec('organismplot', 'setseriesdata', {
"data": [
{
"values":data_update.organisms,
"text":"active",
"background-color":"#2d4962",
"border-width":"1px",
"shadow":0,
"visible":1
},
{
"values":(data_update.totalorganism-data_update.organisms),
"text":"passive",
"background-color":"#2d4962",
"border-width":"1px",
"shadow":0,
"visible":0
}]
I'm a member of the ZingChart team, and I'm happy to help you out!
What is the type of data_update.organisms and data_update.totalorganism-data_update.organisms? Make sure that you are passing a single element array, or if those are simply single values, wrap the variables in brackets to create a single value array for the "values" attribute. E.G.:
"data": [
{
"values":[data_update.organisms], // If data_update.organisms is a single value.
"text":"active",
"background-color":"#2d4962",
"border-width":"1px",
"shadow":0,
"visible":1
},
{
"values":[data_update.totalorganism-data_update.organisms], // Again, single value array.
"text":"passive",
"background-color":"#2d4962",
"border-width":"1px",
"shadow":0,
"visible":0
}
]
I've created a demo using your exact method call, except I've changed the "values" attributes to use a single value array, which are needed for pie charts. Check out the demo here.
I hope that helps. Let me know if you need some more help!

Reducing duplication for JSON test input in RSpec

I'm working on an application that reads JSON content from files and uses them to produce output. I'm testing with RSpec, and my specs are littered with JSON literal content all over the place. There's a ton of duplication, the files are big and hard to read, and it's getting to the point where it's so painful to add new cases, it's discouraging me from covering the corner cases.
Is there a good strategy for me to reuse large sections of JSON in my specs? I'd like to store the JSON somewhere that's not in the spec file, so I can focus on the test logic in the specs, and just understand which example JSON I'm using.
I understand that if the tests are hard to write, I may need to refactor the application, but until I can get the time to do that, I need to cover these test cases.
Below is one modified example from the application. I have to load many different JSON formatted strings like this, many are considerably larger and more complex:
RSpec.describe DataGenerator do
describe "#create_data" do
let(:input){
'{ "schema": "TEST_SCHEMA",
"tables": [
{ "name": "CASE_INFORMATION",
"rows": 1,
"columns": [
{ "name": "case_location_id", "type": "integer", "initial_value": "10000", "strategy": "next" },
{ "name": "id", "type": "integer", "delete_key": true, "initial_value": "10000", "strategy": "next" }
]
}
]
}'
}
it "generates the correct number of tables" do
generator = DataGenerator.new(input)
expect(generator.tables.size).to eq 1
end
end
end
We had a very same problem. We solved it by creating following helpers:
module JsonHelper
def get_json(name)
File.read(Rails.root.join 'spec', 'fixtures', 'json', "#{name}.json")
end
end
We moved all the json into files in spec/fixtures/json folder. Now you will eb able to use it as:
include JsonHelper
let(:input){ get_json :create_data_input }
Naturally you can tweak it as mach as you like/need. For example we were stubbing external services json responses, so we created get_service_response(service_name, request_name, response_type) helper. It is much more readable now when we use get_service_response('cdl', 'reg_lookup', 'invalid_reg')
assuming you put your json into 'create_data_input`

no implicit conversion from nil to integer - when trying to add anything to array

I'm trying to build a fairly complex hash and I am strangely getting the error
no implicit conversion from nil to integer
when I use the line
manufacturer_cols << {:field => 'test'}
I use the same line later in the same loop, and it works no problem.
The entire code is
manufacturer_cols=[]
manufacturer_fields.each_with_index do |mapped_field, index|
if mapped_field.base_field_name=='exactSKU'
#this is where it is breaking, if I comment this out, all is good
manufacturer_cols << { :base_field=> 'test'}
else
#it works fine here!
manufacturer_cols << { :base_field=>mapped_field.base_field_name }
end
end
------- value of manufacturer_fields --------
[{"base_field":{"base_field_name":"Category","id":1,"name":"Category"}},{"base_field":{"base_field_name":"Description","id":3,"name":"Short_Description"}},{"base_field":{"base_field_name":"exactSKU","id":5,"name":"Item_SKU"}},{"base_field":{"base_field_name":"Markup","id":25,"name":"Retail_Price"}},{"base_field":{"base_field_name":"Family","id":26,"name":"Theme"}}]
Implicit Conversion Errors Explained
I'm not sure precisely why your code is getting this error but I can tell you exactly what the error means, and perhaps that will help.
There are two kinds of conversions in Ruby: explicit and implicit.
Explicit conversions use the short name, like #to_s or #to_i. These are commonly defined in the core, and they are called all the time. They are for objects that are not strings or not integers, but can be converted for debugging or database translation or string interpolation or whatever.
Implicit conversions use the long name, like #to_str or #to_int. This kind of conversion is for objects that are very much like strings or integers and merely need to know when to assume the form of their alter egos. These conversions are never or almost never defined in the core. (Hal Fulton's The Ruby Way identifies Pathname as one of the classes that finds a reason to define #to_str.)
It's quite difficult to get your error, even NilClass defines explicit (short name) converters:
nil.to_i
=> 0
">>#{nil}<<" # this demonstrates nil.to_s
=> ">><<"
You can trigger it like so:
Array.new nil
TypeError: no implicit conversion from nil to integer
Therefore, your error is coming from the C code inside the Ruby interpreter. A core class, implemented in C, is being handed a nil when it expects an Integer. It may have a #to_i but it doesn't have a #to_int and so the result is the TypeError.
This seems to have been completely unrelated to anything that had anything to do with manufacturer_cols after all.
I had arrived at the manufacturer_cols bit because if I commented that out, it ran fine.
However, if I commented out the part where I ran through the csv further down the page, it ran fine also.
It turns out the error was related to retrieving attempting to append the base_field when it was nil.
I thought I could use
manufacturer_cols.each do |col|
base_value = row[col[:row_index].to_i]
if col[:merges]
col[:merges].each do |merge|
base_value += merge[:separator].to_s + row[merge[:merge_row_index]]
end
end
end
unfortunately, that caused the error. the solution was
base_value = base_value + merge[:separator].to_s + row[merge[:merge_row_index]]
I hope this helps somebody, 'cause as DigitalRoss alluded to, it was quite a wild goose chase nailing down where in the code this was being caused and why.
I got this error when parsing through an API for "tag/#{idnum}/parents"...Normally, you'd expect a response like this:
{
"parents": [
{
"id": 8,
"tag_type": "MarketTag",
"name": "internet",
"display_name": "Internet",
"angellist_url": "https://angel.co/internet",
"statistics": {
"all": {
"investor_followers": 1400,
"followers": 5078,
"startups": 13214
},
"direct": {
"investor_followers": 532,
"followers": 1832,
"startups": 495
}
}
}
],
"total": 1,
"per_page": 50,
"page": 1,
"last_page": 1
}
but when I looked up the parents of the market category "adult" (as it were), I got this
{
"parents": [ ],
"total": 0,
"per_page": 50,
"page": 1,
"last_page": 0
}
Now ruby allowed a number of interactions with this thing to occur, but eventually it threw the error about implicit conversion
parents.each do |p|
stats = p['statistics']['all']
selector << stats['investor_followers'].to_i
end
selected = selector.index(selector.max)
parents[selected]['id'] ***<--- CODE FAILED HERE
end
This was a simple fix for me.
When I was getting this error using the Scout app, one of my mapped folders was header-1, when I removed the hyphen from the folder name and made it header1, the error went away.
It didn't like the hyphen for some reason...

Resources