Hot answers tagged

6

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::...


4

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: &...


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

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 ...


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

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: "blog", orderBy: "postDate desc") { id, slug, title, uri }, next(section: "blog", orderBy: "...


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

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

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.


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

After trying multiple options found an answer:


2

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 resolvers. Documentation about the required Interfaces: https://craftcms.com/docs/3.x/extend/graphql.html#interfaces Documentation on the folder structure of such a ...


2

GraphQL Mutations are indeed supported in Craft 3.7: https://craftcms.com/docs/3.x/graphql.html#mutations


2

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 to add arguments to existing queries, but that won't be possible until Craft 4.0, so you'll have to add an entirely new query. So, add a custom query and ...


2

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 setup, either.


1

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


1

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.


1

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 for anyone else still struggling like I was, here's the code (thanks to his work) which finally got things working for me: First of all, in your nuxt.config.js ...


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

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

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 Something like this (replacing 'attributeHandle' and "valueYouWant"): query test { entries(section: "vacancies", relatedToEntries({...


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

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 } }


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