Hot answers tagged

5

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\ForbiddenHttpException; // ... // Is this a GraphQL request? if (Craft::$app->request->getActionSegments() == ['graphql', 'api']) { Event::on(EntryQuery::...


3

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 getEntryData($id: [Int]) { prevEntry: entry(prevSiblingOf: 99) { id title slug uri } nextEntry: entry(nextSiblingOf: 99) { id title ...


3

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 for every asset volume that your asset field can pull from. If there are any assets selected in the field which the schema does not have permission to access, ...


2

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 for all hosts (module mode)" in the PHP tab. Thanks to Brandon Kelly from the Craft forum for pointing me in the right direction.


2

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 cache is invalidated. If you're using Nuxt with a static target, your entries will be displayed in the same order until the cache is expired and your app is ...


2

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 is released. see comment by @harrymee123 and my example query at https://github.com/craftcms/cms/issues/5930#issuecomment-657417173


2

Got it working like this: <ng-template ngFor let-obj [ngForOf]="entry.imageHero"> <h1>{{ obj.heroTitle }}</h1> </ng-template> This also works: {{ entry.imageHero[0].heroTitle }}


2

After trying multiple options found an answer:


1

Welp, as they say, "There's a config setting for that" - :facepalm: - If you add the following to your /config/general.php file it will disable GraphQL caching completely: //Disable GraphQL Caching 'enableGraphQlCaching' => false, To reference it from a .env environment variable use this instead: // Disable GraphQL Caching from .env variables '...


1

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


1

This is not possible on Craft 3.3.x but group and groupId have been added since 3.4.0-beta.5 (commit) With the update, you can do: query getAllUsers{ users(groupId:1) { id, username } } Or: query getAllUsers{ users(group:"groupHandle") { id, username } }


1

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 expiryDate ...on sectionHandle_entryTypeHandle_Entry { description } } } Replace sectionHandle and entryTypeHandle with your values, I guess something ...


1

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.


1

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 field name (ex foo:) before it in graphQL. The field name should not be one the object already has as it would overwrite the original field in this case.


1

I might be missing something here but wouldn't passing the current entry's tag IDs rather than the entry ID work for you? query QueryName { entries( section: "article", limit: 2, relatedTo: [123,456] // Current article's tag IDs? ) { id, title } }


1

@littered your example is working when you unwrap the Int param in your query. This should work: query getEntryData($id: Int) { prevEntry: entry(prevSiblingOf: $id) { id title slug uri } nextEntry: entry(nextSiblingOf: $id) { id title slug uri } entryData: entry(section: investigations, id: [$id]) { id ...


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