graphql-ruby: Int isn't a defined input type (on $first) - ruby-on-rails

I’ve got a question I can’t seemingly resolve on my own.
Together with basic Query, Mutation and so on types I’ve made the following type definition:
module Types
UserType = GraphQL::ObjectType.define do
name 'User'
description 'A user'
implements GraphQL::Relay::Node.interface
global_id_field :id
field :email, !types.String, 'Email address'
connection :docs, DocType.connection_type, 'Available docs'
end
end
And I then try to query it with:
query FileListQuery(
$after: String
$first: Int
) {
viewer {
currentUser {
docs(first: $first, after: $after) {
edges {
node {
id
name
__typename
}
cursor
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
id
}
id
}
}
And I pass the following as query variables:
{
"first": 1,
"after": null
}
The problem is it bails out with the following:
{
"errors": [
{
"message": "Int isn't a defined input type (on $first)",
"locations": [
{
"line": 3,
"column": 3
}
],
"fields": [
"query FileListQuery"
]
}
]
}
I honestly have no clue why it complains about the Int type…
If I get rid of the problematic $first query variable in the request, it works fine.
This:
query FileListQuery(
$after: String
) {
viewer {
currentUser {
docs(first: 10, after: $after) {
edges {
node {
id
name
__typename
}
cursor
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
id
}
id
}
}
Produces this:
{
"data": {
"viewer": {
"currentUser": {
"docs": {
"edges": [
{
"node": {
"id": "1",
"name": "First Doc",
"__typename": "Doc"
},
"cursor": "MQ=="
}
],
"pageInfo": {
"endCursor": "MQ==",
"hasNextPage": false,
"hasPreviousPage": false,
"startCursor": "MQ=="
}
},
"id": "1"
},
"id": "VIEWER"
}
}
}
Any hints, ideas on how to fix this? I use the graphql gem v1.6.3.

Currently, there seems to be a bug in graphql-ruby that prevents types not explicitly used in a schema from being propagated. Check out this issue on GitHub: https://github.com/rmosolgo/graphql-ruby/issues/788#issuecomment-308996229
To fix the error one has to include an Int field somewhere in the schema. Turns out I haven't had one. Yikes.
This fixed it for me:
# Make sure Int is included in the schema:
field :testInt, types.Int

Related

How to find ids on array who is created facet operator

I have Customer collection on MongoDB. With status field. Which can have the same Id fields.
And I need find first changed value like 'Guest' and push it Id's to specific pipeline named as 'guests'.
And customers with status 'Member' I need push tu another pipeline named as 'members' who Id'd equal Id's from aggregation pipeline 'guests'.
This is done in order to obtain the quantity elements in 'guests' and 'members'.
Its member item:
{"_id"=>{"$oid"=>"5ce2ecb3ad71852e7fa9e73f"},
"status"=>"member",
"duration"=>nil,
"is_deleted"=>false,
"customer_id"=>"17601",
"customer_journal_item_id"=>"62769",
"customer_ids"=>"17601",
"customer_journal_item_ids"=>"62769",
"self_customer_status_id"=>"21078",
"self_customer_status_created_at"=>"2017-02-01T00:00:00.000Z",
"self_customer_status_updated_at"=>"2017-02-01T00:00:00.000Z",
"updated_at"=>"2019-05-20T18:06:43.655Z",
"created_at"=>"2019-05-20T18:06:43.655Z"}}
My aggregation
{
'$sort': {'self_customer_status_created_at': 1}
},
{'$match':
{
'self_customer_status_created_at':
{
"$gte": Time.parse('2017-01-17').beginning_of_month,
"$lte": Time.parse('2017-01-17').end_of_month
}
}
},
{
"$facet": {
"guests":
[
{
"$group": {
"_id": "$_id",
"data": {
'$first': '$$ROOT'
}
}
},
{
"$match": {
"data.status": "guest"
}
}, {
"$group": {
"_id":nil,
"array":{
"$push": "$data.self_customer_status_id"
}
}
},
{
"$project":{
"array": 1,
"_id":0
}
}
], "members":
[
{
"$group": {
"_id": "$_id", "data": {
'$last': '$$ROOT'
}
}
},
{
"$match": {
"data.status": "member",
"data.self_customer_status_id": {
"$in": [
"$guests.array"
]
}
}
}
}
]
}
}, {
"$project":
{
"members": 1,
"guests.array": 1
}
}
]
).as_json
Instead "guests.array" array? I have error:
Mongo::Error::OperationFailure: $in needs an array (2)
What am I doing wrong?
Sorry my English!
second expression in faced doesnt seen first expression
need delete
,
"data.self_customer_status_id": {
"$in": {
"$arrayElemAt":
[
"$guests.array",
0
]
}
}
{"$match": {"data.self_customer_status_id": { "$in": ["guests.array"] } } }
```
this link paste before $project

How do I view the JSON behind a Google Slide?

I want to know what elements of a slide can be changed programmatically; one way to understand what's going on would be to look at the JSON behind slides. I have the slides ID but haven't figured out how to look at it in any way except the standard wysiwyg editor.
For the whole presentation, you can check this documentation.
JSON representation
{
"presentationId": string,
"pageSize": {
object(Size)
},
"slides": [
{
object(Page)
}
],
"title": string,
"masters": [
{
object(Page)
}
],
"layouts": [
{
object(Page)
}
],
"locale": string,
"revisionId": string,
"notesMaster": {
object(Page)
},
}
And for each page, you can refer to REST Resource: presentations.pages.
JSON representation
{
"objectId": string,
"pageType": enum(PageType),
"pageElements": [
{
object(PageElement)
}
],
"revisionId": string,
"pageProperties": {
object(PageProperties)
},
// Union field properties can be only one of the following:
"slideProperties": {
object(SlideProperties)
},
"layoutProperties": {
object(LayoutProperties)
},
"notesProperties": {
object(NotesProperties)
},
"masterProperties": {
object(MasterProperties)
},
// End of list of possible types for union field properties.
}

Filtered search with Authorization for Elasticsearch

I'm trying to do a search where I look for "test" in any field while filtering for a specific client in the client_id field. Can't seem to figure this one out. This is how fat I got (but it's not working):
{
query: {
filtered: {
query: "test",
filter: {
term: {client_id: #client.id}
}
}
}
}
This is the right syntax
{
"query": {
"filtered": {
"query": {
"match": {
"_all": "test"
}
},
"filter": {
"term": {
"client_id": #client.id
}
}
}
}
}
From ES Docs: The _all field allows you to search for values in documents without knowing which field contains the value

Ruby use find to loop through an array and return the matching value

I am trying to loop through an array using find to find and return a specific id.
This is my structure:
{
"employees": [
{
"emp_id": "1",
"tutorials": [
{
"id": "test1"
},
{
"id": "test2"
},
{
"id": "test3"
},
{
"id": "test4"
},
{
"id": "test5"
}
]
}
]
}
So basically I am trying to see if the above structure contains a tutorial id of 'test3' and return it.(i.e return 'test3' in this case)
I can get the desired result using a combination of map and find like this:
my_tutorial = employees.map { |employee|
employee.tutorials.find { |tutorial|
tutorial.id == 'test3'
}
}.first
my_tutorial
But I want to know if there is a better way using find . I tried the following but it returns the ruby object instead of the id.
employees.find { |employee|
employee.tutorials.find { |tutorial|
tutorial.id == 'test3'
}
}
Here is what i did to make it work using find. Not sure if it is any better:
my_id = employees.find { |employee|
employee.tutorials.find { |tutorial|
tutorial.id == 'test3'
}
}
my_id.tutorials.first.id
If you have to get only the first record do as follows:
employees[0].tutorials.detect {|r| r.id == 'test3' }

Elasticsearch params presence

How do I construct the query JSON so that while filtering it checks for the presence of external params.
{"query": {
"filtered": {
"query": {
"match_all": {}
}}},
"filter": {
"and": {
"filters": [
{
"term": {
"locality_name": params[:locality_name] if params[:locality_name].present?
}
}
]
}
}}:
The if clause in the JSON is invalid syntax for query DSL.
I think you can combine existFilter and termFilter with and filter like this.
This will retrieve documents for which locality_name field exist and locality_name field value is equal to your specified value.
"filter" : {
"and" : [
{
"exists" : { "field" : "locality_name" }
},
{
"term" : { "locality_name" : "your_locality_name" }
}
]
}
http://www.elasticsearch.org/guide/reference/query-dsl/exists-filter/
http://www.elasticsearch.org/guide/reference/query-dsl/and-filter/

Resources