Skip to content

fix playground cannot be used offline #82 #83

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

Open
wants to merge 1 commit 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
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,20 @@ To do this SPQR uses `TypeInfoGenerator` on a global level. When using this star
| graphql.spqr.gui.targetEndpoint | n/a |
| graphql.spqr.gui.targetWsEndpoint | n/a |
| graphql.spqr.gui.pageTitle | GraphQL Playground |

| graphql.spqr.gui.offline | false |

NOTE: If you set `graphic ql.spqr.gui.offline`=`true`, you need to download static files, such as images, CSS files, and JavaScript files, and then put these files in the static directory.
```bash
curl -s https://raw.githubusercontent.com/leangen/graphql-spqr-spring-boot-starter/master/graphql-spqr-spring-boot-autoconfigure/src/main/resources/playground.html | \
grep -oP "cdn.*?[\"|\']" | \
sed "s,['|\"],," | \
while read url ;
do
mkdir -p $url ;
rm -rf $url ;
wget -O $url $url ;
done
```
### Customize mapping of GraphQL values to Java values

Object in charge of doing this in SPQR is `ValueMapperFactory`. Again the simplest way to make use of this when using the starter is to wire a single bean of this type into the application context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public static class Gui {
private String targetEndpoint;
private String targetWsEndpoint;
private String pageTitle = "GraphQL Playground";
private boolean offline = false;

public boolean isEnabled() {
return enabled;
Expand Down Expand Up @@ -268,5 +269,13 @@ public String getPageTitle() {
public void setPageTitle(String pageTitle) {
this.pageTitle = pageTitle;
}

public boolean isOffline() {
return offline;
}

public void setOffline(boolean offline) {
this.offline = offline;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ public GuiController(SpqrProperties config) {
@ResponseBody
@RequestMapping(value = "${graphql.spqr.gui.endpoint:/gui}", produces = "text/html; charset=utf-8")
public String gui() throws IOException {
return StreamUtils.copyToString(new ClassPathResource("playground.html").getInputStream(), StandardCharsets.UTF_8)
String playgroundHtml = StreamUtils.copyToString(new ClassPathResource("playground.html")
.getInputStream(), StandardCharsets.UTF_8)
.replace("${pageTitle}", config.getGui().getPageTitle())
.replace("${graphQLEndpoint}", config.getGui().getTargetEndpoint())
.replace("${webSocketEndpoint}", config.getGui().getTargetWsEndpoint());

return config.getGui().isOffline() ? playgroundHtml.replace("//", "/")
: playgroundHtml;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
</div>
<script>window.addEventListener('load', function (event) {
GraphQLPlayground.init(document.getElementById('root'), {
// options as 'endpoint' belong here
/* options as 'endpoint' belong here */
endpoint: '${graphQLEndpoint}',
subscriptionEndpoint: '${webSocketEndpoint}'
})
})</script>
</body>

</html>
</html>