Skip to main content
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\...
Brandon Kelly's user avatar
4 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 ...
Jake Dohm's user avatar
  • 766
4 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: "...
Oli's user avatar
  • 7,495
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. ...
Jon W's user avatar
  • 81
3 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 ...
davidwebca's user avatar
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 ...
Oli's user avatar
  • 7,495
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 ...
Oli's user avatar
  • 7,495
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) ...
Oli's user avatar
  • 7,495
3 votes

GraphQL query entries by DateTime field between two dates

After trying multiple options found an answer:
Alex89's user avatar
  • 183
3 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.
Chris Clower's user avatar
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 ...
littlered's user avatar
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.
CraftQuest's user avatar
  • 1,122
3 votes
Accepted

GraphQL - Behaviours

You can register your field into GraphQL by TypeManager::EVENT_DEFINE_GQL_TYPE_FIELDS event here is an example: Event::on( TypeManager::class, TypeManager::...
aodihis's user avatar
  • 801
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 ...
gbmillard's user avatar
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 ...
Dalton Rooney's 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 ...
Kirk Roberts's user avatar
2 votes
Accepted

How to return custom fields in GraphQL

For anything else than base element fields, you'll need to use an inline fragment to fetch your custom fields like so: query test { entries(section: "vacancies", limit: 20) { title ...
Oli's user avatar
  • 7,495
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.
Peter L's user avatar
  • 86
2 votes
Accepted

GraphQL two image transforms for same field

Untested, but should work: image { foo: url @transform ([width: 300, immediately: true]) boo: url @transform ([width: 600, immediately: true]) } You can rename fields by just adding a new ...
Denis's user avatar
  • 96
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 ...
Denis's user avatar
  • 96
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....
Trish20's user avatar
  • 31
2 votes
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 ...
Brad Bell's user avatar
  • 67.5k
2 votes

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 ...
ToddPadwick's 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 ...
Andris Sevcenko's 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
Ben Croker's user avatar
  • 7,536
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 ...
Mario's 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 ...
Clive Portman's 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 { ...
Oli's user avatar
  • 7,495
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 ...
jannisborgers's user avatar
2 votes
Accepted

Adding section to Graphql "View - Public Schema" programatically

You can query for elements (entries, users, etc.) using Craft's GraphQL API, but not for collections of elements (sections, user groups, etc.). I already answered a very similar question, see https://...
Ben Croker's user avatar
  • 7,536

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