Hot answers tagged

6 votes
Accepted

GraphQL: Prevent users seeing entries authored by other users

You can do this using a custom module that adds an authorId condition to element queries, for graphql/api requests. use Craft; use craft\elements\db\EntryQuery; use yii\base\Event; use yii\web\...
user avatar
4 votes

Using a GraphQL mutation to append a block to a Neo field

So the work around was to convert the Neo field to a Matrix. That worked for this instance since we're not storing anything complex but I'd sure like to figure out if/how Neo supports mutations. ...
user avatar
  • 81
3 votes
Accepted

Create folder in asset volume via GraphQL

Currently, there’s no direct way of doing this. You can pass an existing folder ID but you can’t create folders on the fly. However, you can create folders via an asset field (with dynamic path) ...
user avatar
  • 7,160
3 votes
Accepted

GraphQL: get prev / next entry from current entry (channel)

You should be able to use next and prev (see documentation and this issue). query getEntryData($id: [QueryArgument]) { entry(id: $id) { id, slug, title, uri, prev(section: "...
user avatar
  • 7,160
3 votes

Fetching Unique Categories related to Entries via GraphQL

You can run a categories query and pass it your product id(s) as well as the category group id (though that's not necessary) to fetch all categories related to your products. The query: query ...
user avatar
  • 7,160
3 votes
Accepted

Updating Entry field with GraphQL mutation

To edit an entry via a GraphQL mutation you will need to pass the id of the entry you want to edit (similar to front end entry form). This example assumes a news Section, an article Entry Type and ...
user avatar
  • 7,160
3 votes

How to get previous and next entry using the native GraphQL API?

So I'm wondering the same thing, I'm using CraftQL as I need to support mutations, and I am close with this - but I get an error if I try to use $id instead of a hard-wired Int (e.g. 99): query ...
user avatar
3 votes
Accepted

Asset field empty in graphql query response

Check that the schema you're querying has permissions to access the asset volumes that your asset field is pulling from. For images to be returned, the schema you are querying must have permissions ...
user avatar
  • 736
3 votes
Accepted

GraphQL IDE doesn't show up in Craft Admin

GraphQL support in Craft requires a Craft Pro license. https://craftcms.com/pricing Do you have one for that project? If you're just working locally, you can enable a trial.
user avatar
2 votes

GraphQL private schema returning public schema scope

It turned out that MAMP Pro was stripping out the Authorization header, so every request was treated as a request to the public schema. The solution for MAMP Pro was to enable "Identical PHP version ...
user avatar
2 votes

How to loop through Craft CMS query in Angular

Got it working like this: <ng-template ngFor let-obj [ngForOf]="entry.imageHero"> <h1>{{ obj.heroTitle }}</h1> </ng-template> This also works: {{ entry....
user avatar
  • 31
2 votes
Accepted

getting active userid by GraphQL?

with a get request from /index.php?p=admin/actions/users/session-info&dontExtendSession=1 I can get my CSRF Code + the User ID. Great.
user avatar
  • 86
2 votes
Accepted

CraftCMS + GraphQL - orderBy Random?

RAND() is the correct way to do this. (At least, it works in 3.5). One catch is that GraphQL queries are cached by default, so your results will always be returned in the same random order until your ...
user avatar
2 votes

In GraphQL how to query entries where related entry has a specific value

I know this question is 1.5+ years old but I landed here looking for something similar and think I found the answer: relatedToEntries. In the docs: https://craftcms.com/docs/3.x/graphql.html#relations ...
user avatar
2 votes
Accepted

Graphql total results / pageinfo when searching with pagination

Try entryCount. You can also add arguments to this, such as section: entryCount(section:"news"), for example.
user avatar
2 votes
Accepted

Query for Lightswitch in GraphQL

Just saw this resolved issue on GitHub: https://github.com/craftcms/cms/issues/5930 So Lightswitch querying should be fixed in the upcoming release CraftCMS 3.5 Edit: there is a workaround until 3.5 ...
user avatar
  • 86
2 votes

GraphQL query entries by DateTime field between two dates

After trying multiple options found an answer:
user avatar
2 votes

Is it possible to write a custom GraphQL resolver for Craft?

So after reaching out to Craft's support, they very kindly pointed out that I had great timing because they had just launched new documentation pages outlining details on how to create GraphQL ...
user avatar
2 votes
Accepted

How do I write a GraphQL query to search through sub-entries/entries as fields and return the whole entry?

Currently, it can't be done out of the box, since it's currently not possible to search the related entries like this. However, you can extend GraphQL to pull this off. Ideally, it would be possible ...
user avatar
2 votes
Accepted

Graphql mutations with json

GraphQL Mutations are indeed supported in Craft 3.7: https://craftcms.com/docs/3.x/graphql.html#mutations
user avatar
  • 6,226
2 votes

How to get enabled entry with GraphQL, enabledForSite has been deprecated?

Info I found this info in a GitHub comment by Brandon Kelly: commented on 30 Jun 2020 The enabledForSite param is now deprecated and set to false by default (as in “don’t worry about it”). It is now ...
user avatar
  • 255
2 votes
Accepted

Return a single element instead of an array in a GraphQL query

No, I don't think so. If you think about it, assets are always an array so treat them consistently as such, even if you've set a limit of one. If the backend limit changes, it won't screw with your ...
user avatar
2 votes
Accepted

How do I get custom fields of User on graphQL?

Users query will return a list of UserInterface objects (docs) so you will need to do something like this: query { users { ... on User { firstName lastName email photo { ...
user avatar
  • 7,160
2 votes
Accepted

How to make a external GraphQL API request?

We solved this ourselves last week when we wanted to query an existing, external GraphQL API from inside a CraftCMS website in Twig without using a GraphQL client. I assume that fetch() in your code ...
user avatar
1 vote

Craft CMS GraphQL count query

Try using _count -- there are some examples here: https://github.com/craftcms/cms/issues/4847
user avatar
1 vote

GraphQL mutation or query, how to target specific site?

Aha, it was merely sending in siteId as well when updating, in addition to id. If siteId is missing, it will default to primary site it seems.
user avatar
  • 213
1 vote

WARNING: heuristic fragment matching going on! when querying matrix fields or any query with multiple fragment types with Graph QL using Nuxt Apollo

I struggled with this for ages, but after @mylesthe.dev (who responded to one of the posts i mention above) spoke to me directly to provide fantastic support and some examples, I figured it out. So ...
user avatar
1 vote

Fetching Unique Categories related to Entries via GraphQL

If I understand correctly you are searching for products with a $searchTerm query variable and you want a separate list of the unique brands related to those products. You could use a categories ...
user avatar
  • 2,573
1 vote
Accepted

How can I have created data (id) returned for a GraphQL mutation?

As noted by yvanavermaet in the comments on the question, this is an issue with Craft. It's been fixed in 3.6.5. Thanks!
user avatar
1 vote
Accepted

Filter for language when using graphQL

You'll want to use siteId for this. query { entries (section: "newsIntranet", siteId: "2") { title postDate expiryDate contentText } } Swap ...
user avatar
  • 66.4k

Only top scored, non community-wiki answers of a minimum length are eligible