Skip to content

Commit

Permalink
feat(apollo): deprecate config value "shouldPrefetchOnServer"
Browse files Browse the repository at this point in the history
And put its successor `allowServerSideDataFetching` into place.
  • Loading branch information
Emanuel Kluge authored and jhiode committed Oct 28, 2019
1 parent 2fc424e commit 2758f43
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ _Reminder: These settings go into your `package.json` or [Hops configuration fil
| `graphqlUri` | `String` | `''` | _yes_ | URI to your GraphQL endpoint or mock server |
| `graphqlSchemaFile` | `String` | `''` | _no_ | Path to your GraphQL schema file |
| `graphqlMockSchemaFile` | `String` | `''` | _no_ | Path to your GraphQL Schema mocks |
| `shouldPrefetchOnServer` | `Boolean` | `true` | _no_ | Whether Hops should execute GraphQL queries during server-side rendering |
| `shouldPrefetchOnServer` | `Boolean` | `true` | _no_ | Whether Hops should execute GraphQL queries during server-side rendering **[deprecated]** |
| `allowServerSideDataFetching` | `Boolean` | `true` | _no_ | Whether Hops is allowed to execute GraphQL queries during server-side rendering |

##### Options

Expand Down
13 changes: 10 additions & 3 deletions packages/apollo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Check out this [integration test](https://github.com/xing/hops/tree/master/packa
| `fragmentsFile` | `String` | `<rootDir>/fragmentTypes.json` | _no_ | Where to store the generated fragment types file |
| `graphqlUri` | `String` | `''` | _yes_ | Url to your GraphQL endpoint or mock server |
| `graphqlSchemaFile` | `String` | `''` | _no_ | Path to your GraphQL schema file |
| `shouldPrefetchOnServer` | `Boolean` | `true` | _no_ | Whether Hops should execute GraphQL queries during server-side rendering |
| `shouldPrefetchOnServer` | `Boolean` | `true` | _no_ | Whether Hops should execute GraphQL queries during server-side rendering **[deprecated]** |
| `allowServerSideDataFetching` | `Boolean` | `true` | _no_ | Whether Hops is allowed to execute GraphQL queries during server-side rendering |

##### `fragmentsFile`

Expand Down Expand Up @@ -91,7 +92,7 @@ In case your GraphQL server (configured via [`graphqlUri`](#graphqluri)) does no
}
```

##### `shouldPrefetchOnServer`
##### `shouldPrefetchOnServer` **[deprecated]**

Whether you want "full server-side rendering" or just "app shell" rendering.

Expand All @@ -103,6 +104,12 @@ This option controls whether you want Hops to execute GraphQL queries during ser
}
```

##### `allowServerSideDataFetching`

If you don't want Hops to do full server-side rendering, set this value to `false`.

Bear in mind, that setting this value to `true` on the other hand has no mandatory character. This means that there's no way to force Hops to execute server-side requests. As soon as there's a single Hops preset in place, that either sets the `allowServerSideDataFetching`-value to `false` or implements the [`canPrefetchOnServer`](https://github.com/xing/hops/tree/master/packages/graphql#canprefetchonserver-boolean-sequence-server)-hook to return `false`, there won't be any server-side requests.

#### Render Options

This preset has only a single runtime option which can be passed to the `render()` options inside the `styled` key (see example above).
Expand Down Expand Up @@ -167,6 +174,6 @@ Allows to get the [fragment matcher](https://www.apollographql.com/docs/react/ad

This is a hook that can be used to customize the behavior of when Hops can prefetch data during server-side rendering. E.g. execute GraphQL queries during initial render. If any function of this sequence returns false it prevents server fetching for this request.

By default it returns whatever is configured in the [`shouldPrefetchOnServer` preset option](#shouldPrefetchOnServer).
By default it returns whatever is configured in the [`allowServerSideDataFetching` preset option](#allowServerSideDataFetching).

In case you need more control over the server-side rendering you can implement this method and provide your own implementation that decides if data should be prefetched during server-side rendering.
15 changes: 13 additions & 2 deletions packages/apollo/mixin.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
sync: { override, callable, sequence },
},
} = require('hops-mixin');
const deprecate = require('depd')('hops-graphql');

const { ApolloProvider, getMarkupFromTree } = require('react-apollo');
const { default: ApolloClient } = require('apollo-client');
Expand Down Expand Up @@ -116,9 +117,19 @@ class GraphQLMixin extends Mixin {
}

canPrefetchOnServer() {
const { shouldPrefetchOnServer } = this.config;
const { shouldPrefetchOnServer, allowServerSideDataFetching } = this.config;

if (typeof shouldPrefetchOnServer === 'boolean') {
deprecate(
'[DEP0003] The config property "shouldPrefetchOnServer" is deprecated and will' +
' be removed in favor of the property "allowServerSideDataFetching" in the next' +
' major release of Hops.'
);
}

return shouldPrefetchOnServer !== false;
return (
shouldPrefetchOnServer !== false && allowServerSideDataFetching !== false
);
}

getTemplateData(data) {
Expand Down
1 change: 1 addition & 0 deletions packages/apollo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"apollo-client": "^2.6.4",
"apollo-link-http": "^1.5.16",
"cross-fetch": "^3.0.4",
"depd": "^2.0.0",
"graphql": "^14.5.8",
"graphql-tools": "^4.0.5",
"hops-config": "^12.0.0-alpha.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo/preset.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
mixins: [__dirname],
fragmentsFile: '<rootDir>/fragmentTypes.json',
shouldPrefetchOnServer: true,
allowServerSideDataFetching: true,
browserWhitelist: {
graphqlUri: true,
},
Expand All @@ -18,7 +18,7 @@ module.exports = {
type: 'string',
absolutePath: true,
},
shouldPrefetchOnServer: {
allowServerSideDataFetching: {
type: 'boolean',
},
},
Expand Down

0 comments on commit 2758f43

Please sign in to comment.