Skip to content
Merged
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
23 changes: 22 additions & 1 deletion playground/src/components/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,35 @@ const PlaygroundPortal = () => {
);
};

function constructGraphQLURL(location: string, graphqlURL: string, playgroundPath: string): string {
const normalizePath = (path: string) => path.replace(/\/+$/, ''); // Remove trailing slashes

let baseURL = location;

// Remove playgroundPath from the end of location
if (baseURL.endsWith(playgroundPath)) {
baseURL = baseURL.slice(0, -playgroundPath.length);
} else if (baseURL.endsWith(playgroundPath + '/')) {
baseURL = baseURL.slice(0, -playgroundPath.length - 1);
}

baseURL = normalizePath(baseURL);
graphqlURL = graphqlURL.startsWith('/') ? graphqlURL : `/${graphqlURL}`;

return baseURL + graphqlURL;
}

export const Playground = (input: {
routingUrl?: string;
hideLogo?: boolean;
theme?: 'light' | 'dark' | undefined;
scripts?: GraphiQLScripts;
fetch?: typeof fetch;
}) => {
const url = input.routingUrl || import.meta.env.VITE_ROUTING_URL || '{{graphqlURL}}';
const url =
input.routingUrl ||
import.meta.env.VITE_ROUTING_URL ||
constructGraphQLURL(window.location.href, '{{graphqlURL}}', '{{playgroundPath}}');

const [isMounted, setIsMounted] = useState(false);
const [view, setView] = useState<PlaygroundView>('response');
Expand Down
1 change: 1 addition & 0 deletions router/core/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ func (r *Router) bootstrap(ctx context.Context) error {
r.playgroundHandler = graphiql.NewPlayground(&graphiql.PlaygroundOptions{
Html: graphiql.PlaygroundHTML(),
GraphqlURL: r.graphqlWebURL,
PlaygroundPath: r.playgroundPath,
ConcurrencyLimit: int64(r.playgroundConfig.ConcurrencyLimit),
})
}
Expand Down
2 changes: 1 addition & 1 deletion router/internal/graphiql/graphiql.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions router/internal/graphiql/playgroundhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type PlaygroundOptions struct {
Html string
GraphqlURL string
PlaygroundPath string
ConcurrencyLimit int64
}

Expand Down Expand Up @@ -43,6 +44,7 @@ func NewPlayground(opts *PlaygroundOptions) func(http.Handler) http.Handler {

func (p *Playground) initPlayground() {
tpl := strings.Replace(p.opts.Html, "{{graphqlURL}}", p.opts.GraphqlURL, -1)
tpl = strings.Replace(tpl, "{{playgroundPath}}", p.opts.PlaygroundPath, -1)
play := []byte(tpl)
p.templateBytes = play
}
Expand Down