Skip to content

Commit

Permalink
docs: Fix NextJS and Gatsby sections on using a GraphQL IDE (#1445)
Browse files Browse the repository at this point in the history
* fix: NextJS and Gatsby getting started steps that were swapped

Only Gatsby provides GraphiQL to explore the API via http://localhost:8000/__graphql. Our NextJS starter doesn't provide something similar, so the section about the using GraphQL Playground is more suitable to it. The section names were inverted.

* fix: A GraphiQL mention instead of GraphQL Playground

But are GraphQL IDEs, but different ones at that.

* fix: NextJS GraphQL API endpont at port 3000 (8000 is Gatsby's)

* chore: Generalize "GraphQL IDE" instead of singling out just GraphiQL

GraphiQL is just for Gatsby so it doesn't make sense to single it out.

* Revert "chore: Generalize "GraphQL IDE" instead of singling out just GraphiQL"

This reverts commit ade518b.

Let's keep this change simple!

* Changing article title

* Changing links

* Update explore-the-faststore-api.mdx

* Update explore-the-faststore-api.mdx

* Update explore-the-faststore-api.mdx

Co-authored-by: PedroAntunesCosta <47991446+PedroAntunesCosta@users.noreply.github.com>
  • Loading branch information
filipewl and PedroAntunesCosta authored Aug 29, 2022
1 parent 4e31837 commit 5cc642c
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 162 deletions.
42 changes: 22 additions & 20 deletions apps/docs/blog/2022-08-05-faststore.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The `search` query has been enhanced to allow cross-selling and upselling of pro

The `PriceRange` component now displays the min/max values centered above the `Slider`'s thumbs and allows for more customizations.

- 🐛 **`PriceRange` track position fixed** - [#1404](https://github.com/vtex/faststore/pull/1404)
- 🐛 **`PriceRange` track position fixed** - [#1404](https://github.com/vtex/faststore/pull/1404)

The track position of the `PriceRange` component has been adjusted for maximum absolute values greater than a hundred.

Expand All @@ -47,54 +47,56 @@ The `search` query has been enhanced to allow cross-selling and upselling of pro

The `Slider` component now includes the `step` prop that allows specifying the interval between the input values.

- 🐛 **`Slider` values are now rounded** - [#1417](https://github.com/vtex/faststore/pull/1417)
- 🐛 **`Slider` values are now rounded** - [#1417](https://github.com/vtex/faststore/pull/1417)
The `Slider` component now displays only rounded values.

- 🐛 **`Slider` thumb elements repositioned** - [#1423](https://github.com/vtex/faststore/pull/1423)
- 🐛 **`Slider` thumb elements repositioned** - [#1423](https://github.com/vtex/faststore/pull/1423)

The `Slider` thumb elements' have been repositioned in the DOM so they can have customized behavior states.

## FastStore API

- 🧹 **Generated schema types updated** - [#1413](https://github.com/vtex/faststore/pull/1413)/[#1431](https://github.com/vtex/faststore/pull/1431)

The generated TS types from the GraphQL schema have been updated.

### VTEX Platform

- 🎉 **Support for Cross Selling now available** - [#1396](https://github.com/vtex/faststore/pull/1396)

The following facets have been added to the existing `Search` query in order to allow cross-selling and upselling products:

- `buy`
- `view`
- `similars`
- `viewAndBought`
- `accessories`
- `suggestions`
- `suggestions`

- 🎉 **New `subscribeToNewsletter` mutation available** - [#1385](https://github.com/vtex/faststore/pull/1385)
The new `subscribeToNewsletter` mutation allows stores to save data to their MasterData newsletter list.

The new `subscribeToNewsletter` mutation allows stores to save data to their MasterData newsletter list.

- 🎉 **New `skuSelector`-related properties added to `ProductGroup`** - [#1407](https://github.com/vtex/faststore/pull/1407)

The `ProductGroup` type now includes the `skuVariations` attribute, which brings with it four new properties:
The `ProductGroup` type now includes the `skuVariations` attribute, which brings with it four new properties:

- `allVariantsByName` - Returns all available options for each SKU variant property, indexed by their name.
- `slugsMap` - Returns the slug for the SKU that matches the currently selected product variations.
- `activeVariations` - Returns the property values for the current SKU.
- `activeVariations` - Returns the property values for the current SKU.
- `availableVariations` - Returns the available options for each varying SKU property, considering the `dominantVariantName` property.

These new properties allow users to query data about SKU specification variants more quickly and are especially handy for implementing SKU Selector components.
- 🐛 **`StoreOffer` resolver fixed** - [#1399](https://github.com/vtex/faststore/pull/1399)

- 🐛 **`StoreOffer` resolver fixed** - [#1399](https://github.com/vtex/faststore/pull/1399)

The `priceCurrency` field from `StoreOffer` now grabs the same info from the current context's sales channel and fetches the correct price currency value.

- 🐛 **Missing Catalog page types now available** - [#1411](https://github.com/vtex/faststore/pull/1411)

The FastStore API now supports the following page types: `SubCategory`, `Collection`, `Cluster`. This should enable stores to render pages that match those types without issues.
The FastStore API now supports the following page types: `SubCategory`, `Collection`, `Cluster`. This should enable stores to render pages that match those types without issues.

- 🐛 **Issues related to Collection pages fixed** - [#1429](https://github.com/vtex/faststore/pull/1429)
- 🐛 **Issues related to Collection pages fixed** - [#1429](https://github.com/vtex/faststore/pull/1429)

Issues when trying to fetch the `StoreCollection.breadcrumbList` field for Collection pages have been fixed. Before detecting the page type of a certain route, the `slufigyRoot` function now checks if the page is a Collection one.

Expand All @@ -119,13 +121,13 @@ The `search` query has been enhanced to allow cross-selling and upselling of pro
- [Analytics on FastStore](/conceptual-guides/analytics-on-faststore) - [#1405](https://github.com/vtex/faststore/pull/1405)
- [Analytics on official starters](/conceptual-guides/analytics-on-official-starters) - [#1405](https://github.com/vtex/faststore/pull/1405)

**UI**
**UI**

- [`AggregateRating`](/reference/ui/molecules/AggregateRating) - [#1395](https://github.com/vtex/faststore/pull/1395)

**API**
**API**

- [Using GraphiQL to explore the FastStore API](/how-to-guides/faststore-api/using-graphiql-to-explore-the-faststore-api) - [#1390](https://github.com/vtex/faststore/pull/1390)
- [Using GraphiQL to explore the FastStore API](/how-to-guides/faststore-api/explore-the-faststore-api) - [#1390](https://github.com/vtex/faststore/pull/1390)
- [Fetching API data on the storefront](/how-to-guides/faststore-api/fetching-api-data) - [#1403](https://github.com/vtex/faststore/pull/1403)

**VTEX Headless CMS**
Expand All @@ -137,7 +139,7 @@ The `search` query has been enhanced to allow cross-selling and upselling of pro
- [Configuring external DNS for a custom domain](how-to-guides/platform-integration/vtex/hosting-a-faststore-vtex-website) - [#1406](https://github.com/vtex/faststore/pull/1406)/[#1422](https://github.com/vtex/faststore/pull/1422)
- [FasStore API overview](/reference/api/faststore-api) - [#1366](https://github.com/vtex/faststore/pull/1366)
- [Extending the GraphQL schema](/how-to-guides/faststore-api/extending-the-faststore-api) - [#1416](https://github.com/vtex/faststore/pull/1416)
- [Using GraphiQL to explore the FastStore API](/how-to-guides/faststore-api/using-graphiql-to-explore-the-faststore-api) - [#1428](https://github.com/vtex/faststore/pull/1428) / [#1432](https://github.com/vtex/faststore/pull/1432)
- [Using GraphiQL to explore the FastStore API](/how-to-guides/faststore-api/explore-the-faststore-api) - [#1428](https://github.com/vtex/faststore/pull/1428) / [#1432](https://github.com/vtex/faststore/pull/1432)

## Internal

Expand All @@ -153,4 +155,4 @@ The `search` query has been enhanced to allow cross-selling and upselling of pro

- 🧹 **Broken documentation links fixed** - [#1424](https://github.com/vtex/faststore/pull/1424)/[#1430](https://github.com/vtex/faststore/pull/1430)

- 🧹 **Changelog configs fixed** - [#1426](https://github.com/vtex/faststore/pull/1426)
- 🧹 **Changelog configs fixed** - [#1426](https://github.com/vtex/faststore/pull/1426)
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
sidebar_position: 1
---

import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'

# Using a GraphQL IDE to explore the FastStore API

You can use [GraphQL](https://graphql.org/) Integrated Development Environments (IDEs) to try out queries and mutations. This means you can explore your store's GraphQL data layer by running a local server of your project.

There are different GraphQL IDEs you can use. In this tutorial, you will learn how to use [graphql-playground](https://github.com/graphql/graphql-playground), but feel free to use another one. It is likely that other IDEs also contain most features described below.

## Getting started

To use a GraphQL playground, you must run your project in a local server and use the local GraphQL path in your GraphQL IDE of choice. Follow the steps below:

1. Clone the [graphql-playground repository](https://github.com/graphql/graphql-playground).
2. Open the terminal and change to the `graphql-playground` root directory.
3. Install dependencies by running the command `yarn`.
4. Change the directory to the `packages/graphql-playground-react` folder.
5. Run the command `yarn` to install dependencies.
6. Run the command `yarn start` to start running `graphql-playground`. Once it is running, it will open a new browser tab with the `graphql-playground` interface on `http://localhost:3000/v2/new`.
![graphql playground interface with endpoint prompt](https://vtexhelp.vtexassets.com/assets/docs/src/7%20graphiql%20gatsby%20workaround___dc8d4ebfc6cd476bdea1c9d4c746b2d2.png)
7. Change the directory to the root of your FastStore project.
8. Run the command `yarn develop`.
9. Enter your local GraphQL path in the endpoint URL field.

It is probably `http://localhost:3000/api/graphql` if you are running a [nextjs.store](https://github.com/vtex-sites/nextjs.store) based project and `http://localhost:8000/api/graphql` if your store is based on the [gatsby.store](https://github.com/vtex-sites/gatsby.store).

10. Click `USE ENDPOINT`.
![graphql playground interface](https://vtexhelp.vtexassets.com/assets/docs/src/8%20graphiql%20gatsby%20workaround___7ce1dd5fcfcd3a3f844e4fad09288512.png)

## Building queries

You can use the text box on the left side to type queries and mutations. When you are done, click the <img alt="Execute query" className="inline w-6" src="https://vtexhelp.vtexassets.com/assets/docs/src/executeQuery___7272503777684ec305975f94ff9f3698.png"/> **Execute Query** button or press `Ctrl + Enter` to submit your request.

:::info
If you are not sure what arguments or fields are allowed or required by some query, press `Ctrl + space` to use autocomplete. It will show you all the available options.
:::

## Passing arguments

You can click `QUERY VARIABLES` at the bottom of the screen to open another text box where you can organize the query variables in JSON format.

Setting the **Query Variables** section is recommended when a query has multiple arguments. Inside the query/mutation parentheses, define the names and types of the variables. Note that the variable names must be preceded by a dollar sign (`$`).

In the following example, `MyFirstQuery` accepts two variables: `$first` of type `Int` and `$after` of type `String`. The exclamation mark after the type indicates that the corresponding variable is required.

Create a JSON object on the Query Variables pane with your variable names and values as key-value pairs.

See this code example:

<Tabs>

<TabItem value="query" label="Query" default>

```graphql
query `MyFirstQuery`($first: Int!, $after: String) {
allProducts(first: $first, after: $after) {
edges {
node {
name
}
}
}
}
```

</TabItem>

<TabItem value="variables" label="Variables" default>

```json
{
"first": 5,
"after": "10"
}
```

</TabItem>

</Tabs>

## Consulting documentation

You can also learn more about the types and fields available by opening up the `DOCS` tab in the upper right corner. There you can search or browse through FastStore API queries, mutations and types in order to read the corresponding descriptions.

:::caution
VTEX is continuously working to ensure that the FastStore API types and fields are documented and available via GraphQL IDEs. However, other APIs and frameworks (e.g., Gatsby, Next.js) may not necessarily be documented this way.
:::

## Checking your query history

The **History** panel provides a list of all previously executed queries. Click the query summary presented on the **History** panel to view it in the editor.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ For those cases, it is possible to extend the FastStore API schema, adding new d
In this guide you will learn how to implement this in your project. You can also view a [summary](#summary) of the expected behavior and a [complete code example](#complete-code-example).

:::info
Once you have implemented the schema extension in your code, you can run a local [test with GraphiQL](/how-to-guides/faststore-api/using-graphiql-to-explore-the-faststore-api).
Once you have implemented the schema extension in your code, you can run a local [test with a GraphQL IDE](/how-to-guides/faststore-api/explore-the-faststore-api).
:::

## Step by step
Expand Down Expand Up @@ -249,4 +249,4 @@ const getEnvelop = async () =>

## Summary

After completing the steps above, the FastStore GraphQL API schema of your project will be extended and you will be able to use your custom API fields in your store. See these other guides to learn how to [test your schema using GraphiQL](/how-to-guides/faststore-api/using-graphiql-to-explore-the-faststore-api) and [fetch API information in your storefront](/how-to-guides/faststore-api/fetching-api-data).
After completing the steps above, the FastStore GraphQL API schema of your project will be extended and you will be able to use your custom API fields in your store. See these other guides to learn how to [test your schema using a GraphQL IDE](/how-to-guides/faststore-api/explore-the-faststore-api) and [fetch API information in your storefront](/how-to-guides/faststore-api/fetching-api-data).
16 changes: 10 additions & 6 deletions apps/docs/docs/how-to-guides/faststore-api/fetching-api-data.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'

# Fetching API data on the storefront

Expand All @@ -14,6 +14,7 @@ The FastStore API extends the data layer of your preferred static site generatio
This means that updating a given product's information on your ecommerce platform does not automatically update the information displayed on a previously built product page. Whenever you wish to update the information displayed on your website according to your ecommerce platform data, you should redeploy your website, which will trigger page re-generation.

We also recommend that you take the time to learn more about data fetching in the context of the framework you are using, by checking the corresponding article:

- [Next.js Data fetching overview](https://nextjs.org/docs/basic-features/data-fetching/overview)
- [Querying data in pages with Gatsby](https://www.gatsbyjs.com/docs/how-to/querying-data/page-query/)

Expand All @@ -29,7 +30,7 @@ Below you can see more details about each step along with code examples.

### 1. Building a query

First, you need to know what API data you want to use on your page and how to structure a GraphQL query to get it. It is a good idea to check the [FastStore API reference on queries](https://www.faststore.dev/reference/api/queries). You can also [use GraphiQL to build and test queries](https://www.faststore.dev/how-to-guides/faststore-api/using-graphiql-to-explore-the-faststore-api) to make sure it works as expected.
First, you need to know what API data you want to use on your page and how to structure a GraphQL query to get it. It is a good idea to check the [FastStore API reference on queries](https://www.faststore.dev/reference/api/queries). You can also [use a GraphQL IDE to build and test queries](https://www.faststore.dev/how-to-guides/faststore-api/explore-the-faststore-api) to make sure it works as expected.

Once you have your query structure, you can pass that as a variable on your code by using the `gql` tag, like in the example below.

Expand Down Expand Up @@ -61,6 +62,7 @@ const query = gql`
Queries must be declared in this way on each page on which you wish to use their data. To reuse query snippets across multiple files, you may use [GraphQL fragments](https://graphql.org/learn/queries/#fragments). In the example below you can see an SEO fragment being used to build the same query as the example above.

Declaring the fragment:

```javascript
import { gql } from '@faststore/graphql-utils'
...
Expand All @@ -76,6 +78,7 @@ export const fragment = gql`
```

Using the fragment, on the same file or a different one:

```javascript
import { gql } from '@faststore/graphql-utils'
...
Expand Down Expand Up @@ -258,6 +261,7 @@ export const querySSR = gql`
### 2. Importing the generated query

Once you have declared your query on the page code, you can trigger the generation of your query types by running this command:

```
yarn generate
```
Expand All @@ -267,6 +271,7 @@ Whenever you make changes to your declared queries you must regenerate the types
:::

Then you must import the types generated, like in this example:

```javascript
import { gql } from '@faststore/graphql-utils'
import type { ProductPageQueryQuery } from '@generated/graphql'
Expand Down Expand Up @@ -307,9 +312,10 @@ After completing the steps described above, your code should look like the examp

:::info
It is also a good idea to see how data fetching is implemented in pages from [FastStore starters](https://www.faststore.dev/starters), such as:

- [Next.js store product page](https://github.com/vtex-sites/nextjs.store/blob/main/src/pages/%5Bslug%5D/p.tsx)
- [Gatsby store product page](https://github.com/vtex-sites/gatsby.store/blob/main/src/pages/%5Bslug%5D/p.tsx)
:::
:::

```javascript
import { gql } from '@faststore/graphql-utils'
Expand Down Expand Up @@ -347,5 +353,3 @@ const query = gql`
}
`
```


Loading

1 comment on commit 5cc642c

@vercel
Copy link

@vercel vercel bot commented on 5cc642c Aug 29, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.