Wix GraphQL API

 

Developer Preview - This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
 

The Wix GraphQL API exposes Wix REST APIs as a single unified GraphQL schema, allowing you to query and mutate data from the Wix Platform with all the benefits of GraphQL.

🐣 New to GraphQL? Check out the GraphQL Documentation to learn more.

The Wix SDK allows you to consume the Wix GraphQL API easily, with built-in support for authentication, type inference and more.

Usage

📚 For the full documentation and API reference for the Wix GraphQL API, visit the Wix GraphQL API Documentation.

An initialized WixClient exposes a graphql function that can be used to query and mutate data from the Wix GraphQL API. The graphql function accepts a GraphQL query or mutation and returns a Promise that resolves to the result of the query or mutation.

Copy
1
import { createClient, OAuthStrategy } from '@wix/sdk';
2
3
const wix = createClient({
4
auth: OAuthStrategy({
5
clientId: 'YOUR_CLIENT_ID',
6
})
7
});
8
9
const { data, errors } = await wix.graphql(`
10
query Products($filter: JSON!) {
11
storesProductsV1Products(queryInput: { query: { filter: $filter }}) {
12
items {
13
name
14
}
15
}
16
}
17
`, {
18
filter: {
19
name: {
20
$startsWith: query || ''
21
}
22
},
23
})

Type Inference

The graphql function also supports type inference for the result and variables of a GrahphQL query. If you are using a solution for type inference in your project (such as GraphQL Code Generator) you can pass the inferred types to the graphql function and it will use them to type the result and variables of the query.

Copy
1
import { createClient, OAuthStrategy } from '@wix/sdk';
2
import { graphql } from './generated';
3
4
const wix = createClient({
5
auth: OAuthStrategy({
6
clientId: 'YOUR_CLIENT_ID',
7
})
8
});
9
10
const productsQuery = graphql(`
11
query Products($filter: JSON!) {
12
storesProductsV1Products(queryInput: { query: { filter: $filter }}) {
13
items {
14
name
15
}
16
}
17
}
18
`);
19
20
// The result of the query will be typed as the result of the query
21
// and the variables will be verified against the variables of the query
22
const { data, errors } = await wix.graphql(productsQuery, {
23
filter: {
24
name: {
25
$startsWith: query || ''
26
}
27
},
28
});
Was this helpful?
Yes
No