graphQl - Argument has invalid value Expected \"contentfulStranNaslovQueryString_2\", found not an object - javascript

I am trying to query some data from a contentful API using gatsby's built-in graphiQL.
EDIT: after a suggestion from the comments, I made a introspection query to get the schema information:
{
"name": "contentfulStranNaslovQueryString_2",
"kind": "INPUT_OBJECT"
}
When I run this query:
{
contentfulStran {
id
naslov
}
}
I get the expected result (the first entry for the data model):
{
"data": {
"contentfulStran": {
"id": "c2tD44y2tDe8QC4yqkwMOgo",
"naslov": "Novice"
}
}
}
But now I would like to pass in a query parameter that only gets data specified on the naslov field. I tried this:
{
contentfulStran(naslov: "Ponudba") {
id
naslov
}
}
But I am getting the following error:
{
"errors": [
{
"message": "Argument \"naslov\" has invalid value \"Ponudba\".\nExpected \"contentfulStranNaslovQueryString_2\", found not an object.",
"locations": [
{
"line": 2,
"column": 27
}
]
}
]
}
What am I doing wrong?

Miha answered his own question in the comments. The correct way to filter is:
{
contentfulStran(naslov: {eq: "Ponudba"})
{
id
naslov
zaporedje
tekst
{
tekst
}
}
}
Note the {eq: "param"} object instead of just giving the param.

Related

Elasticsearch, how to get a search result in all circumstances

I've been dealing with a project. My goal is to get result from search engine in all circumstances for example, although i enter a keyword which is not include the keys inside data or is a empty string, I still need to get some result.How can i reach my goal?
you can see the query below :
query: {
regexp: {
title: "something to not found .*",
},
Try use "prefix" or "query_string"
You also can use title.keyword for exact value
1 -
{
"query": {
"prefix": {
"title": {
"value": "<data>"
}
}
}
}
2 -
{
"query": {
"query_string": {
"default_field": "title",
"query": "<data>*^0"
}
}
}

How do you check if value exists and then either add or update values in firebase with JavaScript?

I have an app where users can log in and add trips they've been on. my fb db structure is like so
{
"users": {
"randomId": {
"Place1": {
"name": "Place1",
"somedata": "oianoiasnfianafs",
"moredata": "asdasdadasdas",
"THISKEYIWANTTOUPDATE": [
{
"data": "asasfas"
}
]
}
}
}
}
you can see the key above I want to update. but my problem is, I first need to check if Place1 already exists in the database? how do I achieve this? I know I could call set but not sure if this is the best thing to do? I'm also aware of update but I want logic like this pseudo code below
if (place1) {
// call update()
} else {
// cat set()
}
I'm not sure how to do the if(place1) part though? and if it's best practice in firebase to check if it exists?
You could try use Object.keys(obj) to get attribute of object.
assume that userObj is
"users": {
"randomId": {
"Place1": {
"name": "Place1",
"somedata": "oianoiasnfianafs",
"moredata": "asdasdadasdas",
"THISKEYIWANTTOUPDATE": [
{
"data": "asasfas"
},
]
},
}
}
and you have mentioned that it could be mulitple PlaceN under randomID, then I suggest that the pattern might be :
multiple case, have Place2 and value of Place1 is null:
"randomId": {
"Place1": {
},
"Place2": {
"name": "Place2",
"somedata": "oianoiasnfianafs",
"moredata": "asdasdadasdas",
"THISKEYIWANTTOUPDATE": [
{
"data": "asasfas"
},
]
},
}
and the check function:
checkPlace1ExistOrNot=(userObj)=>{
let tempRandomId = userObj[Object.keys(userObj)[0]] //It should be vale of "RandomId"
if(tempRandomId[Object.keys(tempRandomId)[0]])
{
return true // users.randomId.Place1 is exist
}
else
{
return false // users.randomId.Place1 is not exist
}
}

Javascript Google Classroom API

I'm trying to access the Google Classroom API with Javascript and am running into a syntax problem when trying to create a student.
The relevant code is
function createStudent () {
var course_id = '146694xxx'
var enrollment_code = '7ytxxx'
var student = {
userId: 'xxx#gmail.com'
}
student = gapi.client.classroom.courses.students.create({courseId:course_id,enrollmentCode:enrollment_code, params: student}).execute();
}
The problem is with the named parameter for the student object. It is where I have "params". I have tried every name I can think of like requestBody, body and a million others. The error I get is
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"params\" at 'student': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "student",
"description": "Invalid JSON payload received. Unknown name \"params\" at 'student': Cannot find field."
}
]
}
]
}
}
How should I be representing that request body object in the call?
Thanks.
Harry

Elastic Search query for email

I am trying to implement email search with ElasticSearch.
Here are the example documents.
{
...
"email": "valeri#gmail.com"
},
{
...
"email": "tom#gmail.com"
}
So when I use the match query: { "match": { "email": "valeri#gmail.com"
} }
I get both of "valeri#gmail.com"and "tom#gmail.com" but the result must be only "valeri#gmail.com".
I think it is because of # character.
Any good solution to resolve this issue?
You need to use the Email Tokenizer as specified here:
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-uaxurlemail-tokenizer.html
Use this to make your request 👍
GET my_index/_search
{
"query": {
"match_phrase_prefix" : {
"email": "valery#gmail.com"
}
}
}
You will have the expecting result

Node.js: Extract data from JSON response

I'm fetching product details using an API which gives the response as a JSON object.
{
"productBaseInfo": {
"productIdentifier": {
"productId": "EKTDDD23232zYHR94E4",
},
"productAttributes": {
"title": "Nova KT 72BC 1 Electric Kettle",
"imageUrls": {
"400x400": "http://img5a.flixcart.com/image/electric-kettle/4/e/4/nova-kt-722-c-kt-722c-400x400-imadddh2fdvuzpxz.jpeg",
"75x75": "http://img6a.flixcart.com/image/electric-kettle/4/e/4/nova-kt-722-c-kt-722c-75x75-imadddh2fdvuzpxz.jpeg",
},
"sellingPrice": {
"amount": 599.0,
"currency": "INR"
},
"productUrl": "http://dl.mykart.com/dl/nova-kt-722c-1-electric-kettle/p/itmdddf398rhhhz2?pid=EKTDDDEGXYHR94E4&affid=userid"
}
}
}
Now I want to get the productId, title in ProductAttributes, and all the image urls and productURL.
I tried
var productURL = JSON["productAttributes"].productUrl
But it returns an error productUrl not found error. Looking for suggestion on how to extract the data. Thanks in advance.
productAttributes is inside productBaseInfo. So you need to access it like this
console.log(JSON.productBaseInfo.productAttributes.productUrl);
// http://dl.mykart.com/dl/nova-kt-722c-1-electric-kettle/p/itmdddf398rhhhz2?pid=EKTDDDEGXYHR94E4&affid=nikhilgeo

Categories