How to filter in datahub graphql? - graphql

I’m using the data hub function with GraphQL to fetch data for external systems, but I have problems with filters for nested objects.
Taking the example of docs, in the products endpoint of the demo, I make this call and I get all cars called E-Type.
{
getCarListing(filter: "{'name' : 'E-Type'}"){
edges{
node{
name
manufacturer{
… on object_Manufacturer{
name
}
}
}
}
}
}
How can I filter on manufacturer name? I was thinking to this filter:
filter : "{'manufacturer' : {'name' : 'Jaguar'}}".
This return me column_name name not found response.
Can anybody please help me solve this?

found a response in this ticket: https://github.com/pimcore/data-hub/issues/224#issuecomment-628514018
Here they state, that this feature is currently not supported by PimCore. Maybe it will be supported in the future.

Related

How to query a map of id with graphql?

I am trying to query an array of ids with graphQl. The query works with a single id as a variable. However it doesn't work when I enter an array of ids.
Here is my gql query with variables:
query GetAuthorContent($id: [ID]!, $idType: AuthorIdType) {
expert(id: $id, idType: $idType) {
excerpt
featuredImage {
node {
description
author {
node {
description
}
}
}
}
slug
}
}
{"id": ["author-1", "author-2", "author-3"], "idType": "SLUG" }
You can look at the definition of the graphql endpoint using a client and see if the Arrays are supported with query.
If it's supported, check the mutation signature and pass accordingly. In this case I think the services does not support querying using an Array.
Hi everyone and thank you for your help.
You guys were right, my DB doesn't allow an array of authors if it is per author singular. However it works with authors plural. This is the way my db works.
Hope it can help someone in the same situation.

GraphQL; select all records

The service provider for an ERP software recently implemented GraphQL for those customers who wish to use their data beyond the tools they provide. I was asked to investigate its usefulness in creating digests of this data into more user-friendly data formats (excel, google sheets, ect ... )
While experimenting with the API using Altair I've run across a situation I don't understand, as I'm approaching the challenge as I would a RDMS:
{
__type(name:"Jobs") {
fields {
name
description
}
}
}
The above returns all the fields for the object 'Jobs'. For this examples, it returns a list of fields: JobNo, PartNo, PartRev, CustomerID, DueDate
I wanted to return a list of existing 'JobNo' in the Jobs object, so I tried the query:
{
Jobs {
JobNo DueDate
}
}
Which resulted in:
{
"errors": [
"Expected a non-null value for argument \"JobNo\" on field \"Jobs\"."
]
}
If I use the following query:
{
Jobs(JobNo:"12345")
{
JobNo DueDate
}
}
I get results, but its not very useful as I would have to know something about the contents of the data.
Is there a way of querying for ALL JobNo? Or is the purpose of GraphQL to know at least some specifics of the data, like the JobNo, before constructing your query?
Thank you.

shopify storefront api doesn't show filter results as expected

I'm building an app using shopify Storefront api. So far I'm able to fetch products, collections. But when I try to filter the products in a collection it is not returning results as expected. Here is what i'm trying in postman
{
collection(id:"Z2lkOi8vc2hvcGlmeS9Db2xsZWN // collection id"){
products(first:10, filters:[{productVendor:"ADDIDAS"}]){
edges{
node{
id
title
description
productType
vendor
}
}
}
}
}
But i'm getting results that have vendor of NIKE and other types. Do i need to change something?
But when i try filter using price it works fine but when i try filtering using productType it is giving me not expected results. Am i doing something wrong?
Please help here

How can I query my data by published date (newest first) using Apollo and Graphql?

I have React page that is fetching data via Graphql.
I'm using Strapi as backend and queries are already generated.
I´m querying my data in the frontend like this
query GetData{
datas(limit:3){
id
published_at
}
}
In the documentation I found this example about how to sort my queries by some especific order
GET /users?_sort=email:ASC,dateField:DESC
but is not really clear how to use it with the query structure.
I tried something like this and other variations
query GetPodcasts{
podcasts?_sort=published_at:DESC(limit:3){
id
published_at
}
}
but it didn't work.
I may need some help understanding this.
In a forum some nice people also gave me an answer.
When using graphql in frontend and want to sort or filter the data, just have to use "" to specify the sort or filter.
In my case it just had to be:
query GetData{
datas(limit:3, sort:"published_at:desc"){
id
published_at
}
}
Graphql is like an Rest Api but with one end point to the server ,
this query with name GetData , point to datas query but you should define this query in the backend.
please watch some tutorials that will guide you step by step.
you can learn more about graphql here
https://graphql.org/learn/
try this:
query GetData{
datas(input:{
sort:{id:"asc"},
data:{limit:3}
}){
id
published_at
}
}
for more info
https://strapi.io/documentation/developer-docs/latest/development/plugins/graphql.html#query-api
This seem to work for me in Strapi v4:
sort: "publishedAt:DESC"
...
query GetVideos($page: Int!, $pageSize: Int!) {
videos(
pagination: { page: $page, pageSize: $pageSize }
sort: "publishedAt:DESC"
) {
__typename
data {
__typename
id
attributes {
__typename
createdAt
publishedAt
}
}
}
}
}
`

GraphQL: Is it possible to search nested field?

I am specifically using the shopify graphql admin api to query orders.
I want to do a search for a nested related field.
Below is my query.
export const orderHistoryQuery = gql`
query Order($productsFirst: Int!, $productsAfter: String, $filterQuery: String) {
orders(first: $productsFirst, after: $productsAfter, reverse: true, query:$filterQuery) {
edges {
cursor
node {
id
name
customer {
id
metafields(first: 10) {
edges {
node {
id
key
value
namespace
}
cursor
}
}
}
totalPriceSet {
shopMoney {
amount
currencyCode
}
}
subtotalPriceSet {
shopMoney {
amount
currencyCode
}
}
totalRefundedSet {
shopMoney {
amount
currencyCode
}
}
currencyCode
email
phone
processedAt
totalShippingPriceSet {
shopMoney {
amount
currencyCode
}
}
totalTaxSet {
shopMoney {
amount
currencyCode
}
}
shippingAddress {
firstName
lastName
address1
address2
city
province
zip
country
}
billingAddress {
firstName
lastName
address1
address2
city
province
zip
country
}
customAttributes {
key
value
}
}
}
}
}
`;
I want to query metafields or ANYTHING really but it doesn't seem like it's supported. I am not sure if I just have the wrong query syntax or if it's not supported. The shopify search syntax documenation doesn't really help and this is where my knowledge of graphql falls apart.
Is it possible to do this in graphql? I also tried adding metafields(id: $whateverID) which is not supported by their setup.
Unfortunately, Shopify doesn't support query filters on metafields. The best way to figure this out is by using a graphql explorer like GraphiQL. Shopify dashboard has this built in if you go to Apps > Shopify GraphiQL App.
Using GraphiQL you can see that:
Customers query doesn't have metafields supported:
Orders query doesn't have customers or metafields supported:
And metafields on customers doesn't have a query param:
I think your options are to either query by what you can and filter after you get the results or use a customer tag and query by tag.
You would really help your cause out by simplifying things. My advice to you is to try a simple query. Can you get an order? Since an order has a customer (usually but not always), can you get a metafield associated with that customer?
You have so many obstacles in your attempt to show what you are trying to do, it is almost as if you want a migraine headache in trying to debug anything. GraphQL calls to endpoints are documented fairly well from the GraphQL website perspective, and Shopify is nothing but a vanilla implementation of that, with the caveat that they charge you for calls based on complexity, so you had best be monitoring your credits.
So ya, try simple calls. Get a product and it's Metafields. Get a customer record and it's Metafields. If you can do that, you are not challenging the documentation much, nor the concept of GraphQL queries. Once a basic all works, you can work in variables, cursors, paging, etc... but until a one-off call gives you what you want, debugging should be concentrated on the simplest of calls, not everything and the kitchen sink.
Also, when you screw up a call to the endpoint, Shopify usually returns a response with details about where you screwed up, providing you with a first place to look. We see nothing of your response, so there is little to go on to help you.

Resources