graphql get query shows this error "variables are not allowed in scalars" - graphql

query describeNotesByNameSpaace($id:bigint!) {
notes(where: {object_meta: {_contains: {owner_references: [{uid:$id}]}}}) {
id
}
}

Use below code
query describeNotesByNameSpace($jsonFilter: jsonb) {
notes(where: {object_meta: {_contains: $jsonFilter}}) {
id
}
}
And query variable is
{
"jsonFilter": {
"owner_references": [
{
"uid": "1719430910876008448"
}
]
}
}

Related

GitHub GraphQL API Read custom field in Project V2

We are using Github Projects V2. I have created a custom field say 'MyCustomField'.
I want to read the value of custom field MyCustomField using Github GraphQL API.
I am following Gtihub GraphQL API Docs
So far I have got till reading a few predefined fields on Gtihub Issues like title, url, assignees and labels. I am using Windows PowerShell:
$project_id="MyProjectIDFetchedUsingDifferentQuery"
gh api graphql -f query='
query($project_id: ID!){
node(id: $project_id) {
... on ProjectV2 {
items(last: 20) {
nodes{
id
content{
...on Issue {
title
url
assignees(first: 10) {
nodes{
login
}
}
labels(first:5) {
edges {
node {
name
}
}
}
}
}
}
}
}
}
}' -f project_id=$project_id
I am not able to find a way to get the custom field MyCustomField.
I am expecting to write some query like below:
$project_id="MyProjectIDFetchedUsingDifferentQuery"
gh api graphql -f query='
query($project_id: ID!){
node(id: $project_id) {
... on ProjectV2 {
items(last: 20) {
nodes{
id
content{
...on Issue {
title
url
assignees(first: 10) {
nodes{
login
}
}
labels(first:5) {
edges {
node {
name
}
}
}
customFields(first:5) {
nodes {
name
}
}
}
}
}
}
}
}
}' -f project_id=$project_id
I came up with this which I think should get the custom fields on your board:
query {
node(id: "(my project id)") {
... on ProjectV2 {
items(last: 20) {
nodes {
id
content {
... on Issue {
title
url
state
assignees(first: 10) {
nodes {
login
}
}
}
}
fieldValues(first: 20) {
nodes {
... on ProjectV2ItemFieldSingleSelectValue {
field {
... on ProjectV2SingleSelectField {
name
}
}
name
id
}
... on ProjectV2ItemFieldLabelValue {
labels(first: 20) {
nodes {
id
name
}
}
}
... on ProjectV2ItemFieldTextValue {
text
id
updatedAt
creator {
url
}
}
... on ProjectV2ItemFieldMilestoneValue {
milestone {
id
}
}
... on ProjectV2ItemFieldRepositoryValue {
repository {
id
url
}
}
}
}
}
}
}
}
}
Credit should go to https://stackoverflow.com/users/2312060/rich-kuzsma for posting https://gist.github.com/richkuz/e8842fce354edbd4e12dcbfa9ca40ff6
This had the basic format for querying ProjectV2 fields, and I added the
ProjectV2SingleSelectField bit to include both the field name and its value in the response.

How to reformat result in graphql?

I have a query like this:
query GetProductsBySlug {
categories(
where:{slug: "pianos"}
) {
products (first: 2) {
id,
slug,
name,
price,
images(first: 1) {
url
}
}
}
}
Results from this query:
{
"data": {
"categories": [
{
"products": [
{
...
]
}
]
}
}
I want to remove "data":...", "categories":..., and only get this result:
{
"products": [
{
...
}]
}
How I can do it?
I want that result only include {"products": ...} without data and categories.
You can use just [destructuring assignment][1] and get just the categories like
const {data:{categories}} = queryResult;
and then map this categories array like
categories.map(category=> category.products)
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

Spring Boot Mongo update nested array of documents

I'm trying to set an attribute of a document inside an array to uppercase.
This is a document example
{
"_id": ObjectId("5e786a078bc3b3333627341e"),
"test": [
{
"itemName": "alpha305102992",
"itemNumber": ""
},
{
"itemName": "beta305102630",
"itemNumber": "P5000"
},
{
"itemName": "gamma305102633 ",
"itemNumber": ""
}]
}
I already tried a lot of thing.
private void NameElementsToUpper() {
AggregationUpdate update = AggregationUpdate.update();
//This one does not work
update.set("test.itemName").toValue(StringOperators.valueOf(test.itemName).toUpper());
//This one also
update.set(SetOperation.set("test.$[].itemName").withValueOfExpression("test.#this.itemName"));
//And every variant in between these two.
// ...
Query query = new Query();
UpdateResult result = mongoTemplate.updateMulti(query, update, aClass.class);
log.info("updated {} records", result.getModifiedCount());
}
I see that Fields class in spring data is hooking into the "$" char and behaving special if you mention it. Do not seem to find the correct documentation.
EDIT: Following update seems to work but I do not seem to get it translated into spring-batch-mongo code
db.collection.update({},
[
{
$set: {
"test": {
$map: {
input: "$test",
in: {
$mergeObjects: [
"$$this",
{
itemName: {
$toUpper: "$$this.itemName"
}
}
]
}
}
}
}
}
])
Any solutions?
Thanks!
For now I'm using which does what i need. But a spring data way would be cleaner.
mongoTemplate.getDb().getCollection(mongoTemplate.getCollectionName(Application.class)).updateMany(
new BasicDBObject(),
Collections.singletonList(BasicDBObject.parse("""
{
$set: {
"test": {
$map: {
input: "$test",
in: {
$mergeObjects: [
"$$this",
{
itemName: { $toUpper: "$$this.itemName" }
}
]
}
}
}
}
}
"""))
);

Unknown Type of Strapi/Gatsby Graphql Query Fragment

I'm trying to query data within a Strapi Dynamic Zone in Gatsby. In the Graphql Playground I can get this to work, but using the same query in Gatsby I receive the following error in the terminal:
error Unknown type "ComponentTextArticleCopy" graphql/template-strings
And my query in article.js
export const query = graphql`
query ArticleTemplate($id: String!) {
strapiArticle(id: { eq: $id }) {
articleHeader {
articleTitle
articleSnippet
}
articleContent {
__typename
... on ComponentTextArticleCopy {
contentCopy
}
... on ComponentImageContentImg {
imgCaption
}
... on ComponentTextArticleQuote {
contentQuote
}
}
}
}
`
According to the Graphql docs, Inline Fragment would seem to be the right approach but clearly I've got something wrong somewhere.
The following query 'works' on Gatsby but tries to resolve for all components:
query MyQuery {
allStrapiArticle {
edges {
node {
__typename
articleContent {
contentCopy
contentQuote
}
}
}
}
}
{
"data": {
"allStrapiArticle": {
"edges": [
{
"node": {
"__typename": "StrapiArticle",
"articleContent": [
{
"contentCopy": null,
"contentQuote": null
},
{
"contentCopy": "What a great city Gothenburg is. We even took a trip out to the archipelago. ",
"contentQuote": null
},
{
"contentCopy": null,
"contentQuote": null
},
{
"contentCopy": null,
"contentQuote": "You must visit at have fika"
}
]
}
}
]
}
},
Deleting Cache folder and running again worked for me.

Drupal GraphQL - Query Single Entity from URL

Is it possible to get an article(single entity) using the Url Alias (entityUrl.path)?
I am using https://github.com/drupal-graphql/graphql
I can do a bulk query for all the articles, do I then filter those results?
Thanks
query GetArticles {
nodeQuery(filter: {conditions: [{field: "type", value: "article"}]}) {
Articles: entities {
entityId
entityLabel
entityUrl {
path
routed
}
}
}
}
Figured it out
query ($path: String!) {
route:route(path: $path) {
... on EntityCanonicalUrl {
entity {
... on Node {
nid
entityLabel
body{
value
}
}
}
}
}
}

Resources