Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Moon): use custom mutation fn #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
#### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [Moon team](mailto:amen.souissi@decathlon.com). All complaints will be reviewed and investigated and will result in a response that
reported by contacting the project team at [Moon team](mailto:amen.souissi@pricemoov-oss.com). All complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Contributing to @decathlon/moon
## Contributing to @pricemoov-oss/moon

First off, thanks for taking the time to contribute!

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2020 Decathlon
Copyright 2020 PricemoovOSS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Table of contents
Installation for Axios client
============================
```bash
npm install @decathlon/moon @decathlon/moon-axios react-query axios --save
npm install @pricemoov-oss/moon @pricemoov-oss/moon-axios react-query axios --save
```


Expand All @@ -54,12 +54,12 @@ Usage

You get started by create REST links. A link is an object which need an id and an HTTP client config like the AxiosConfig (that extends the Moon's ClientConfig) of your REST server (for more information about the REST link config please see the **Moon config** section).

To connect Moon to your React app, you will need to use the MoonProvider component exported from `@decathlon/moon`. The MoonProvider is a React's Context.Provider. It wraps your React app and places the client and the store (the query cache of the **react-query**) on the context, which allows you to access it from anywhere in your component tree. You also need to add the HTTP client factory (**clientFactory**). Here we have added the Axios factory to create an axios client for each link. You can also add a client factory for each link. This is useful for using multiple data sources or for mocking data during development phase (tests, mvp...).
To connect Moon to your React app, you will need to use the MoonProvider component exported from `@pricemoov-oss/moon`. The MoonProvider is a React's Context.Provider. It wraps your React app and places the client and the store (the query cache of the **react-query**) on the context, which allows you to access it from anywhere in your component tree. You also need to add the HTTP client factory (**clientFactory**). Here we have added the Axios factory to create an axios client for each link. You can also add a client factory for each link. This is useful for using multiple data sources or for mocking data during development phase (tests, mvp...).


```js
import { MoonProvider } from "@decathlon/moon";
import axiosClientFactory from "@decathlon/moon-axios";
import { MoonProvider } from "@pricemoov-oss/moon";
import axiosClientFactory from "@pricemoov-oss/moon-axios";

const links = [
{
Expand All @@ -85,7 +85,7 @@ Query
-----

```js
import { Query } from "@decathlon/moon";
import { Query } from "@pricemoov-oss/moon";

const MyComponent = () => {
return (
Expand All @@ -112,7 +112,7 @@ useQuery
The same query with the **useQuery** hook

```js
import { useQuery } from "@decathlon/moon";
import { useQuery } from "@pricemoov-oss/moon";

const MyComponent = () => {
const [{ isLoading, error }, { refetch }] = useQuery<QueryVariables, QueryResponse, QueryData, QueryError>({
Expand All @@ -136,7 +136,7 @@ usePrefetchQuery
If you're lucky enough, you may know enough about what your users will do to be able to prefetch the data they need before it's needed! If this is the case, you can use the usePrefetchQuery hook. This hook return a prefetch function to prefetch the results of a query to be placed into the cache:

```js
import { usePrefetchQuery } from "@decathlon/moon";
import { usePrefetchQuery } from "@pricemoov-oss/moon";

const MyComponent = ({page}) => {
const prefetchQuery = usePrefetchQuery<QueryVariables, QueryResponse, QueryData>({
Expand All @@ -156,7 +156,7 @@ useInfiniteQuery
---------------

```js
import { useInfiniteQuery } from "@decathlon/moon";
import { useInfiniteQuery } from "@pricemoov-oss/moon";

interface QueryData {
comments: any;
Expand Down Expand Up @@ -200,7 +200,7 @@ Mutation useMutation
Now that we've learned how to fetch data with the Query/useQuery component/hook, the next step is to learn how to mutate that data with mutations. For that we need to use the Mutation/useMutation component/hook.

```js
import { Mutation } from '@decathlon/moon';
import { Mutation } from '@pricemoov-oss/moon';

const MyComponent = () => {
return (
Expand All @@ -217,7 +217,7 @@ const MyComponent = () => {
The same mutation with **useMutation**:

```js
import { useMutation } from '@decathlon/moon';
import { useMutation } from '@pricemoov-oss/moon';

const MyComponent = () => {
const [{ error, data }, { mutate }] = useMutation<MutationResponse, MutationVariables>({
Expand Down Expand Up @@ -245,7 +245,7 @@ useQueryState
Updated when the query state is changed. The optional **stateToProps** function is used for selecting the part of the data from the query state that the connected component needs.

```js
import { useQueryState } from '@decathlon/moon';
import { useQueryState } from '@pricemoov-oss/moon';

const MyComponent = () => {
const stateToProps = (queryState) => queryState // optional
Expand All @@ -258,7 +258,7 @@ const MyComponent = () => {
The first prop is the query id used by the query. If the query is defined without an id then the id generated by default must be used. To generate an identifier, you must use the **getQueryId** utility. The default id is generated from the source, the endPoint and the variables props of the query.

```js
import { useQueryState, getQueryId } from "@decathlon/moon";
import { useQueryState, getQueryId } from "@pricemoov-oss/moon";

const MyComponent = () => {
const queryId = getQueryId({ source: "FOO", endPoint: "/users", variables: { foo: "bar" } });
Expand All @@ -274,7 +274,7 @@ useQueriesStates
Updated when one of the query states is changed.The optional **statesToProps** function is used for selecting the part of the data from the query state that the connected component needs.

```js
import { useQueriesStates } from '@decathlon/moon';
import { useQueriesStates } from '@pricemoov-oss/moon';

const MyComponent = () => {
const statesToProps = (queriesStates) => queriesStates
Expand All @@ -289,7 +289,7 @@ useQueryResult
Updated only when the query result is changed. .The optional **resultToProps** function is used for selecting the part of the data from the query result that the connected component needs.

```js
import { useQueryResult } from '@decathlon/moon';
import { useQueryResult } from '@pricemoov-oss/moon';

const MyComponent = () => {
const resultToProps = (queryResult) => queryResult // optional
Expand All @@ -305,7 +305,7 @@ useQueriesResults
Updated only when one of the query results is changed. The optional **statesToProps** function is used for selecting the part of the data from the queries results that the connected component needs.

```js
import { useQueriesResults } from '@decathlon/moon';
import { useQueriesResults } from '@pricemoov-oss/moon';

const MyComponent = () => {
const resultsToProps = (queriesResults) => queriesResults
Expand All @@ -319,7 +319,7 @@ useMoon
You can use the moon client directly like this:

```js
import { useMoon } from '@decathlon/moon';
import { useMoon } from '@pricemoov-oss/moon';

const MyComponent = () => {
const { client, store } = useMoon();
Expand All @@ -338,7 +338,7 @@ withMoon
Same as useMoon hook.

```js
import { withMoon } from '@decathlon/moon';
import { withMoon } from '@pricemoov-oss/moon';

interface Props extends IMoonContextValue {
prop: string;
Expand All @@ -357,7 +357,7 @@ withQueryResult
Same as useQueryResult hook.

```js
import { withQueryResult } from '@decathlon/moon';
import { withQueryResult } from '@pricemoov-oss/moon';

interface Props {
queryResult: QueryState<QueryResponse, QueryError>;
Expand All @@ -377,7 +377,7 @@ withQueriesResults

Same as useQueriesResults hook.
```js
import { withQueriesResults } from '@decathlon/moon';
import { withQueriesResults } from '@pricemoov-oss/moon';

interface Props {
queriesResults: {
Expand Down Expand Up @@ -497,7 +497,7 @@ For each Moon link we can add interceptors (middleware: language, api token, suc

```js
import { AxiosRequestConfig } from "axios";
import axiosClientFactory from "@decathlon/moon-axios";
import axiosClientFactory from "@pricemoov-oss/moon-axios";

function successHandler(response: AxiosResponse){...};

Expand Down Expand Up @@ -569,8 +569,8 @@ up the merging process.
* **Benjamin Wintrebert** [Ben-Wintrebert](https://github.com/Ben-Wintrebert)
* **Hyacinthe Knobloch** [hyacintheknobloch](https://github.com/hyacintheknobloch)

See also the list of [contributors](https://github.com/Decathlon/moon/graphs/contributors) who participated in this project.
See also the list of [contributors](https://github.com/PricemoovOSS/moon/graphs/contributors) who participated in this project.

## License

This project is licensed under the Apache-2.0 License - see the [LICENSE.md](https://github.com/Decathlon/moon/blob/master/LICENSE) file for details
This project is licensed under the Apache-2.0 License - see the [LICENSE.md](https://github.com/PricemoovOSS/moon/blob/master/LICENSE) file for details
12 changes: 6 additions & 6 deletions packages/moon-axios/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# @decathlon/moon-axios
# @pricemoov-oss/moon-axios

_**The power of react-query with Axios**_

**@decathlon/moon** is the [Axios](https://github.com/axios/axios) HTTP client for [Moon](https://github.com/Decathlon/moon).
**@pricemoov-oss/moon** is the [Axios](https://github.com/axios/axios) HTTP client for [Moon](https://github.com/PricemoovOSS/moon).

## Installation

```bash
npm install @decathlon/moon @decathlon/moon-axios react-query axios --save
npm install @pricemoov-oss/moon @pricemoov-oss/moon-axios react-query axios --save
```

## Usage

Please see the [Moon doc](https://github.com/Decathlon/moon/blob/master/README.md) for more details.
Please see the [Moon doc](https://github.com/PricemoovOSS/moon/blob/master/README.md) for more details.

```js
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
import { MoonProvider, ILink } from "@decathlon/moon";
import axiosClientFactory from "@decathlon/moon-axios";
import { MoonProvider, ILink } from "@pricemoov-oss/moon";
import axiosClientFactory from "@pricemoov-oss/moon-axios";

function successHandler(response: AxiosResponse){...};

Expand Down
14 changes: 7 additions & 7 deletions packages/moon-axios/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "@decathlon/moon-axios",
"name": "@pricemoov-oss/moon-axios",
"version": "1.0.3",
"description": "Axios for moon",
"author": "Decathlon",
"author": "PricemoovOSS",
"license": "Apache-2.0",
"main": "lib/moon-axios/src/index.js",
"module": "dist/index.es.js",
"jsnext:main": "dist/index.es.js",
"types": "dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/Decathlon/moon.git"
"url": "git+https://github.com/PricemoovOSS/moon.git"
},
"bugs": {
"url": "https://github.com/Decathlon/moon/issues"
"url": "https://github.com/PricemoovOSS/moon/issues"
},
"homepage": "https://github.com/Decathlon/moon/blob/master/README.md",
"homepage": "https://github.com/PricemoovOSS/moon/blob/master/README.md",
"files": [
"dist",
"lib"
Expand All @@ -24,11 +24,11 @@
"qs": "~6.9.4"
},
"peerDependencies": {
"@decathlon/moon": "~3.0.0",
"@pricemoov-oss/moon": "~3.0.0",
"axios": "~0.20.0"
},
"devDependencies": {
"@decathlon/moon": "^3.0.0"
"@pricemoov-oss/moon": "^3.0.0"
},
"scripts": {
"build": "rimraf dist && rollup -c && npm run build:lib",
Expand Down
2 changes: 1 addition & 1 deletion packages/moon-axios/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosInterceptorManager } from "axios";
import * as qs from "qs";
import { IInterceptors, ClientInstance } from "@decathlon/moon";
import { IInterceptors, ClientInstance } from "@pricemoov-oss/moon";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const paramsSerializer = (params: any) => qs.stringify(params, { arrayFormat: "repeat" });
Expand Down
12 changes: 6 additions & 6 deletions packages/moon-graphql/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# @decathlon/moon-graphql
# @pricemoov-oss/moon-graphql

_**The power of react-query with graphql**_

**@decathlon/moon** is the [graphql](https://github.com/prisma-labs/graphql-request) HTTP client for [Moon](https://github.com/Decathlon/moon).
**@pricemoov-oss/moon** is the [graphql](https://github.com/prisma-labs/graphql-request) HTTP client for [Moon](https://github.com/PricemoovOSS/moon).

## Installation

```bash
npm install @decathlon/moon @decathlon/moon-graphql react-query graphql graphql-request --save
npm install @pricemoov-oss/moon @pricemoov-oss/moon-graphql react-query graphql graphql-request --save
```

## Usage

Please see the [Moon doc](https://github.com/Decathlon/moon/blob/master/README.md) for more details.
Please see the [Moon doc](https://github.com/PricemoovOSS/moon/blob/master/README.md) for more details.

```js
import { MoonProvider, ILink } from "@decathlon/moon";
import graphqlClientFactory from "@decathlon/moon-graphql";
import { MoonProvider, ILink } from "@pricemoov-oss/moon";
import graphqlClientFactory from "@pricemoov-oss/moon-graphql";

function successHandler(response){...};

Expand Down
14 changes: 7 additions & 7 deletions packages/moon-graphql/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "@decathlon/moon-graphql",
"name": "@pricemoov-oss/moon-graphql",
"version": "1.0.1",
"description": "GraphQL for moon",
"author": "Decathlon",
"author": "PricemoovOSS",
"license": "Apache-2.0",
"main": "lib/moon-graphql/src/index.js",
"module": "dist/index.es.js",
"jsnext:main": "dist/index.es.js",
"types": "dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/Decathlon/moon.git"
"url": "git+https://github.com/PricemoovOSS/moon.git"
},
"bugs": {
"url": "https://github.com/Decathlon/moon/issues"
"url": "https://github.com/PricemoovOSS/moon/issues"
},
"homepage": "https://github.com/Decathlon/moon/blob/master/README.md",
"homepage": "https://github.com/PricemoovOSS/moon/blob/master/README.md",
"files": [
"dist",
"lib"
Expand All @@ -24,12 +24,12 @@
"qs": "~6.9.4"
},
"peerDependencies": {
"@decathlon/moon": "~3.0.0",
"@pricemoov-oss/moon": "~3.0.0",
"graphql": "~15.3.0",
"graphql-request": "~3.4.0"
},
"devDependencies": {
"@decathlon/moon": "^3.0.0"
"@pricemoov-oss/moon": "^3.0.0"
},
"scripts": {
"build": "rimraf dist && rollup -c && npm run build:lib",
Expand Down
2 changes: 1 addition & 1 deletion packages/moon-graphql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GraphQLClient } from "graphql-request";
import { RequestInit } from "graphql-request/dist/types.dom";
import { IInterceptors, ClientInstance } from "@decathlon/moon";
import { IInterceptors, ClientInstance } from "@pricemoov-oss/moon";

export interface GraphQLRequestConfig {
params?: Record<string, any>;
Expand Down
Loading