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

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 will update the entry title. Mutation mutation MyMutation($id: ID = "", $title: String = "") { save_news_article_Entry(id: $id, title: $title)...


3

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) attached to an entry type so there is an option that could work if you really need this done. Create a section/entry type that has two fields, an Asset field with a ...


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

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


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

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 getRelatedBrands($relatedTo: [QueryArgument] = "", $groupId: [QueryArgument] = "") { categories(groupId: $groupId, relatedTo: $relatedTo) { id ...


2

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. mutation addRecipeReview($recipeId: ID, $blocks: [reviews_MatrixBlockContainerInput] = {review: {authorEmail: "", authorName: "", authorReview: &...


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

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!


1

You'll want to use siteId for this. query { entries (section: "newsIntranet", siteId: "2") { title postDate expiryDate contentText } } Swap out "2" with whatever the siteId of the French site is on your system.


1

If you want live and pending entries, you would need to pass status to your query with the values you want (docs). query yourQuery { entries(section: "yourSectionHandle", status: ["live", "pending"]) { title } } Or if you want to use variables: query yourQuery($section: [String], $status: [String]) { entries(section: $...


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