Skip to content

Conversation

@alanpoulain
Copy link
Member

No description provided.

core/graphql.md Outdated
They are following the GraphQL type system.
If you don't define the `args` property, it will be the default ones (for example `id` for an item).

You can also note that:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note also that:?

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature! GraphQL support starts to be very convenient.

core/graphql.md Outdated
If you move forward, you'll end up having an empty result.

## Mutations
### Custom queries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Custom queries
### Custom Queries

core/graphql.md Outdated
}
```

### Custom mutations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Custom mutations
### Custom Mutations

core/graphql.md Outdated

### Custom mutations

Creating custom mutations is like creating the [custom queries](#custom-queries).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Creating custom mutations is like creating the [custom queries](#custom-queries).
Creating custom mutations is like creating [custom queries](#custom-queries).

*
* @return Book
*/
public function __invoke($item, array $context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, iterable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the context? I think having an array is enough.

core/graphql.md Outdated
The GraphQL endpoint will be able to query only the name. It will only be able to create a book with an author.
When doing this mutation, the author of the created book will not be returned (the name will be instead).
## Custom types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Custom types
## Custom Types

core/graphql.md Outdated
To use it please [modify the extracted types](#modify-the-extracted-types) or use it directly in [custom queries](#custom-queries) or [custom mutations](#custom-mutations).
## Modify the extracted types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Modify the extracted types
## Modifying the Extracted Types

@milosa
Copy link
Contributor

milosa commented Jun 25, 2019

I have been trying to add a custom query the way it is described in this PR.
I added this to my Product entity:

 * @ApiResource(graphql={
 *     "collectionQuery"={
 *         "collection_query"=ProductCollectionResolver::class
 *     }
 *     })

resolver:

    /**
     * @param Product[] $collection
     * @param array $context
     * @param ProductRepository $productRepository
     * @return Product[]
     */
    public function __invoke($collection, array $context, ProductRepository $productRepository)
    {
        return $productRepository->findProductsByTagCollection(1);
    }

I expected this to just add an extra query, but what happens is that it completely removes all the default queries and mutations (create, update, delete) related to the Product entity and the inputs and payloads for them.

Maybe I'm doing something wrong?

@alanpoulain
Copy link
Member Author

Yes you need to add them too, like REST custom actions: https://api-platform.com/docs/core/operations/#recommended-method

@alanpoulain alanpoulain merged commit d5160a3 into api-platform:master Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants