I am using a module controller to create Entries, like this:
$personEvent = new Entry(); $personEvent->sectionId = 6; $personEvent->typeId = 1; $personEvent->authorId = $user->id; $personEvent->enabled = true; $personEvent->setFieldValues([ 'persons' => [$person->id], 'events' => [$event->id], 'group' => @$participant['group'], 'leader' => @$participant['leader'], ]); $success = Craft::$app->elements->saveElement($personEvent);
This works as expected.
When I try to grab the Entries using the GraphiQL explorer they do not appear, despite being shown in the Entries admin panel. If I create an Entry in the same section using the admin panel that Entry can be seen in GraphiQL. The difference seems to be that one was created programmatically while the other was created through the admin panel.
How can I make programmatically created elements available to GraphQL?
EDIT: Updated the title/question, as it seems like it should be default behavior that GraphQL can "see" programmatically created Entries, so I must be missing something.
EDIT 2: I should have mentioned that I have already invalidated the GraphQL data caches and set
'enableGraphqlCaching' => false in config/general.php, just in case that would make a difference.
EDIT 3: Added the
setFieldValues portion of the code. Previously I was using the older
$entry->customField = 'foo' approach. Updating to
setFieldValues does not appear to have made a difference with new programmatically saved entries as far as being able to access them in GraphiQL. Also of note, I am using Full Schema in GraphiQL.