api-platform / api-platform/core

[GraphQl] Support for unions and interfaces for search functionality

未關閉
#2,927 5 則留言 4 個 reaction 已指派 0 人 在 GitHub 檢視
GraphQL
主要語言
PHP
星號
2.6k
分支
980
平均合併
2 天 4 小時
30 天內合併 PR
49

描述

I am trying to create a general search functionality in my app that can return multiple types of objects. For each type of object I want to retrieve different fields.

In the graphQl specification this is supported using interfaces and unions. See this example below:
```GraphQl
type Query {
# Search across all content
search(query: String!): [SearchResult]
}

union SearchResult = Conference | Festival | Concert | Venue
```

```GraphQl
query {
search(query: "Madison") {
... on Venue {
id
name
address
}

... on Festival {
id
name
performers
}

... on Concert {
id
name
performingBand
}

... on Conference {
speakers
workshops
}
}
}
```
See [this guide](https://docs.aws.amazon.com/appsync/latest/devguide/interfaces-and-unions.html) for more details.

I tried making all my entities extend a 'base' entity and creating the search query on that entity, but that did not work.

Thanks in advance!

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。