I have the following query :
{
allPeople {
people {
name
filmConnection {
films {
title
}
}
}
}
}
I would like to select all people that have a film connection with the title a new hope. How do i select this specific thing from the API. I could also just get it like this and handle it in the code. But surely there is a better way.
What i'd expect :
{
allPeople {
people {
name
filmConnection {
films {
title : "a new hope"
}
}
}
}
}
That didnt work..
Try out here in this playground :
https://graphql.org/swapi-graphql?query=%7B%0A%20%20allPeople%20%7B%0A%20%20%20%20people%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20filmConnection%20%7B%0A%20%20%20%20%20%20%20%20films%20%7B%0A%20%20%20%20%20%20%20%20%20%20title%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A
graphql queries ... are not for building [sql] queries ;)
this is more for defining shape of required data
parameter CAN BE passed to deeper child (f.e. can be used to filter films)
{
allPeople {
people {
name {
filmConnection {
films(title_eq:"a new hope") {
title
}
}
}
}
}
}
... if API supports this kind of filtering for films
... but it won't filter people - you'll have all people AND filtered films (for all people) because filters won't work on parents.
You CAN have custom API that will be this kind of filtering aware, f.e.
{
allPeople {
people(connectedFilmTitle_eq:"a new hope") {
name {
filmConnection {
films {
title
}
}
}
}
}
}
customized (not automatically gnerated) peolpe resolver can make appriopriate query [on joined tables] and return structure you're asking for.
In that case probably you don't need deeper structures - ...filmConnection { films { title - you know this data earlier (filter parameters).
... but probably you have a many2many relation and cen reverse this query:
{
allFilms {
films(title_eq:"a new hope") {
title {
peoleConnection {
people {
name
}
}
}
}
}
}
Related
Asset Hotspots have 'add Data' in context menu.
We can add related objects / fileds / documents / etc there.
How to export this data in GraphQL? I see only '__typename' property.
Sample query:
{
getCategoryListing(defaultLanguage: "en") {
totalCount
edges {
node {
categoryimage {
image {
fullpath
}
hotspots {
name
top
height
left
width
data {
__typename
}
}
marker {
name
top
left
data {
__typename
}
}
}
}
}
}
}
Yes, this functionality is provided by GraphQL itself.
Check that you granted reading rights to object class that you are trying to access otherwise you will see 'object: null'
learch which object types you get using __typename
When you know the type name and have access to that object, just get its data
Sample:
... on property_text {
type
name
text
}
or
... on object_product {
sku
}
See the documentation here: https://pimcore.com/docs/data-hub/current/GraphQL/Query/Query_Samples/Sample_Element_Properties.html
Sample query to get additional data from Pimcore Hotspots and Markers on Hotspotimage:
{
getCategoryListing(defaultLanguage: "en") {
totalCount
edges {
node {
id
categoryimage {
image {
fullpath
}
hotspots {
name
top
height
left
width
data {
__typename
... on property_text {
type
name
text
}
... on property_object {
type
name
object {
__typename
... on object_product {
sku
}
... on element {
__typename
}
}
}
}
}
marker {
name
top
left
data {
__typename
... on property_text {
type
name
text
}
... on property_object {
type
name
object {
__typename
... on object_product {
sku
}
}
}
}
}
}
}
}
}
}
I'm new to GraphQL. I was going through the documentation and found something which I feel is odd.
The way to pass data to variables in fragments is to do it through the root query the fragments are part of. The example given in the docs is repeated here for convenience.
query HeroComparison($first: Int = 3) {
leftComparison: hero(episode: EMPIRE) {
...comparisonFields
}
rightComparison: hero(episode: JEDI) {
...comparisonFields
}
}
fragment comparisonFields on Character {
name
friendsConnection(first: $first) {
totalCount
edges {
node {
name
}
}
}
}
My question is, why does HeroComparison define the parameter to be passed down to the enclosed fragments and not the fragments directly? We use the variables in the fragments, so shouldn't it be something like this?
query HeroComparison {
leftComparison: hero(episode: EMPIRE) {
...comparisonFields($first: Int = 3)
}
rightComparison: hero(episode: JEDI) {
...comparisonFields($first: Int = 3)
}
}
fragment comparisonFields on Character {
name
friendsConnection(first: $first) {
totalCount
edges {
node {
name
}
}
}
}
Since this is repetitive, we may even do something like
query HeroComparison {
leftComparison: hero(episode: EMPIRE) {
...comparisonFields
}
rightComparison: hero(episode: JEDI) {
...comparisonFields($first: Int = 2)
}
}
fragment comparisonFields on Character {
*var $first: Int
name
friendsConnection(first: $first = 3) {
totalCount
edges {
node {
name
}
}
}
}
My main concern in asking this is what if we wanted the first instantiation of comparisonFields to get the value 3 and the second to get 2 in the same query?
The docs page mentioned nothing to this end.
Also, aren't the second and third approaches better from the standpoint of separation of concerns?
Pros and Cons of your approach are discussed in detail in this issue.
If we have an Author with no beacons to Articles and thus WroteArticles was null and we wanted to only return Authors who had non-empty/non-null WroteArticles, how could that be done?
As an example we can use the Weaviate demo site
I've tried filter operations using where and various operators, but I must be missing something obvious. Example of a query I've tried on my own data set below, where I did have a Thing with no beacons.
{
Get {
Things {
Author (where:{
operator:Equal,
path:["WroteArticles"]
valueString:" "
}){
name
WroteArticles {
... on Article {
InPublication {
... on Publication {
name
}
}
}
}
}
}
}
}
You can now do this as follows (also in the documentation):
{
Get {
Things {
Author(
where:{
valueInt: 2
operator:GreaterThanEqual
path: ["WroteArticles"]
}
) {
name
WroteArticles {
... on Article {
title
}
}
}
}
}
}
Basically I want to get localized values for the entries linking to my unique entry.
movie(id: $movieId) {
linkedFrom {
spanishMovieLocations: movieLocationCollection(locale: "es-ES") {
items {//fields with localized values}
}
}
}
But instead I get no results in my collection array. Querying directly for movieLocationCollection(locale: "es-ES") gets me localized values and has some matching movie.sys.id that is used in $movieId.
This works fine, but then I dont get the localized fields I need.
movie(id: $movieId) {
linkedFrom {
movieLocationCollection {
items {//fields with non-localized values}
}
}
}
from the contentful site:
We ... made the querying of localized reference content easier by introducing a new allowedLocales argument.
https://www.contentful.com/blog/2020/12/03/three-new-graphql-features-2020/
movie(id: $movieId) {
linkedFrom(allowedLocales: ["es-ES"]) {
movieLocationCollection {
items {//fields with non-localized values}
}
}
}
In my project I had to include both locales
query ($parner: String) {
partnerCollection(limit: 1, locale: "fr-CA", where: {title: $parner}) {
items {
title
sys {
id
}
linkedFrom(allowedLocales: ["en-US", "fr-CA"]) {
benefitCollection(limit: 3) {
total
items {
title
}
}
}
}
}
}
I'm trying to use Gatsby's /___graphq debugger and the README file for gatsby-source-prismic says you can return slices. So below I'm returning the slice with a name PrismicProductBodySteps.
{
allPrismicHomePage {
edges {
node {
data {
seo_title
body {
__typename
... on PrismicProductBodySteps {
}
}
}
}
}
}
}
}
Can someone explain to me what ... on PrismicProductBodySteps means ?
In a gatsby component I've seen this as an example.
body {
... on PrismicProductsBodySteps {
...ProductStepsFragment
}
Can anyone explain to me what the ...ProductStepsFragment means ?
PrismicProductBodySteps would be a custom node type name representing a dynamic series of content blocks. That custom node type name is coming from a Prismic data model; yours will likely be different.
According to the gatsby-source-prismic documentation, using custom node type names requires you to figure out what they are first:
The easiest way to get the type of nodes is to use the /___graphql
debugger and run the below query (adjust the document type and field
name).
{
allPrismicPage {
edges {
node {
id
data {
body {
__typename
}
}
}
}
}
}
Once you have your custom node type name, you can use a GraphQL fragment to pull data specific to each fragment. Again, this would depend on how you have the fragments defined in your data model, but it would look something like this:
{
allPrismicHomePage {
edges {
node {
data {
seo_title
body {
__typename
... on PrismicYourContentBlockOne {
text {
html
}
}
... on PrismicYourContentBlockTwo {
text {
html
}
}
... on PrismicYourContentBlockThree {
text {
html
}
}
}
}
}
}
}
}