Events
17 Mar, 9 pm - 21 Mar, 10 am
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
APPLIES TO: All API Management tiers
The publish-event
policy publishes an event to one or more subscriptions specified in a GraphQL API schema. Configure the policy in a GraphQL resolver for a related field in the schema for another operation type such as a mutation. At runtime, the event is published to connected GraphQL clients. Learn more about GraphQL APIs in API Management.
Note
Set the policy's elements and child elements in the order provided in the policy statement. Learn more about how to set or edit API Management policies.
<http-data-source>
<!-- http-data-source is an example resolver policy -->
<http-request>
[...]
</http-request>
<http-response>
[...]
<publish-event>
<targets>
<graphql-subscription id="subscription field" />
</targets>
</publish-event>
</http-response>
</http-data-source>
Name | Description | Required |
---|---|---|
targets | One or more subscriptions in the GraphQL schema, specified in target subelements, to which the event is published. |
Yes |
http-response
element in http-data-source
resolverpublish-event
policy on a source query or mutation is sufficient to trigger subscription events.The following example policy definition is configured in a resolver for the createUser
mutation. It publishes an event to the onUserCreated
subscription.
type User {
id: Int!
name: String!
}
type Mutation {
createUser(id: Int!, name: String!): User
}
type Subscription {
onUserCreated: User!
}
<http-data-source>
<http-request>
<set-method>POST</set-method>
<set-url>https://contoso.com/api/user</set-url>
<set-body template="liquid">{ "id" : {{body.arguments.id}}, "name" : "{{body.arguments.name}}"}</set-body>
</http-request>
<http-response>
<publish-event>
<targets>
<graphql-subscription id="onUserCreated" />
</targets>
</publish-event>
</http-response>
</http-data-source>
For more information about working with policies, see:
Events
17 Mar, 9 pm - 21 Mar, 10 am
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register now