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

changing /graphql location #6

Closed
srini85 opened this issue Sep 7, 2017 · 35 comments
Closed

changing /graphql location #6

srini85 opened this issue Sep 7, 2017 · 35 comments

Comments

@srini85
Copy link

srini85 commented Sep 7, 2017

Looks like this is not quite working as its supposed to. My understanding is that we need to change the js file aswell if we specify an alternate location

in index.html

function graphQLFetcher(graphQLParams) {
        // This example expects a GraphQL server at the path /graphql.
        // Change this to point wherever you host your GraphQL server.
        return fetch('/graphql', {
          method: 'post',
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
          },

Wanted to see if I could fix it but ran into issues when I tried to reference the source as a project reference.

I pulled the source and did a build, when I referenced the project, I couldn't get the graphiql page to load. The /graphql endpoint was just not serving up the static pages.. Not too sure why. The dll in nuget definitely works so wondering if that is a different version to what is in master?

@josephwoodward
Copy link
Owner

Hi @srini85,

Thanks for raising this, I'll have to take a look to confirm then get back to you.

@simonpetty
Copy link

@srini85 it seems ok when running the example project. what was your plan with this? i'm not sure how best to templatize the html, since it's just an embedded file

@srini85
Copy link
Author

srini85 commented Sep 25, 2017

@simonpetty want to use an alternative location to /graphql. I was thinking of doing it at build time by setting it in the configuration json and then using that as part of the build process. However I couldn't get the project working when I built it myself. So hence wondering if the nuget version is different to the the master src.

@josephwoodward
Copy link
Owner

josephwoodward commented Sep 26, 2017

Another option would be to use the .NET Core proxy library to capture requests to a custom endpoint and proxy them to /graphql.

@srini85 Were you working from a fresh clone of master? I've just did a hard reset (git reset --hard origin/master) to master, then a dotnet restore then ran (using dotnet run) the samples project then navigated to http://localhost:5000/graphql/ and can confirm it works.

How are you launching it?

@josephwoodward
Copy link
Owner

@srini85 I've just tried launching Graphiql from a custom location (/hello instead of the default /graphql) and can confirm that it does work. Can you provide a repository of what you're trying to do so I can take a look?

@srini85
Copy link
Author

srini85 commented Sep 26, 2017

@josephwoodward I will see if I get time to push that repository I was working with. Maybe I am missing something, but deffinately did work of a fresh clone of master with no changes. But if you are confirming that it deffinately does work, perhaps I am missing some step or my environment is not quite right. I will continue to dig and let you know the result.

Just out of curiousity, when you said it worked, are you referring to graphiql loading or loading and making requests to the server? Seeing that the fetch promise is set to /graphql, wondering how that gets updated if your controller location is set to something like /hello (as per the original issue comment)?

@josephwoodward
Copy link
Owner

josephwoodward commented Sep 27, 2017

@srini85 It's done here, allowing you to serve files from a specific location.

@simonpetty
Copy link

The graphiql page loads but the post when submitting a query doesn't work. Another idea is to use an InMemoryFileProvider for the JavaScript currently in the html page, which we can modify with the correct path. Will try to get a version of this going.

@josephwoodward
Copy link
Owner

josephwoodward commented Sep 28, 2017

@simonpetty Weird, I'm sure I tried posting a query, I'll take another look and check it out. I think there are a few options we could use to get that working, such as the proxy which I mentioned above.

@PeterHageus
Copy link

Another option would be to use the .NET Core proxy library to capture requests to a custom endpoint and proxy them to /graphql.

This does not work when hosting under IIS virtual directory. For me a path relative to graphiql would solve the issue...

@poulad
Copy link
Contributor

poulad commented Feb 18, 2018

I also am trying to change the routes to /foo/graphiql and /bar/graphql. The problem is client side requests are always made for /graphql path.

https://github.com/JosephWoodward/graphiql-dotnet/blob/979199d78ab4c393617416eb4e7cc3605032c5ec/src/graphiql/assets/index.html#L112

@josephwoodward
Copy link
Owner

Yeah, this seems to be the biggest blocker. I'm considering adding a template string to the index.html then doing a replace on it, something like:

return fetch('{{ graphqlPath }}', { 

Seems like the easiest option.

@poulad
Copy link
Contributor

poulad commented Feb 19, 2018

@josephwoodward That should work. Do you think we would have a release anytime soon?

@josephwoodward
Copy link
Owner

@pouladpld Hopefully either this week or next by the latest.

@poulad
Copy link
Contributor

poulad commented Feb 19, 2018

Can't wait 😄 I'll try making a PR.

@FrankyBoy
Copy link
Contributor

FrankyBoy commented Aug 7, 2018

Hello. Could we please get this issue addressed? We are facing the same issue, as Graphql is part of a versioned solution (so it runs as my.service.com/1.0/graphql). Actually simply removing the path from here https://github.com/JosephWoodward/graphiql-dotnet/blob/master/src/graphiql/assets/index.html#L112 should do the trick as it then makes a request to the resource itself. That should satisfy all cases, regardless if you are hosting under a completely custom URL or "just" in a subdirectory like we are.

FrankyBoy added a commit to FrankyBoy/graphiql-dotnet that referenced this issue Aug 7, 2018
@josephwoodward
Copy link
Owner

Have an open PR for this (#23) which I'm currently testing an will release in the next few days.

@josephwoodward
Copy link
Owner

josephwoodward commented Aug 20, 2018

This has now been released as a beta package, if you would mind giving it a try and reporting back if you find any issues. You can find the beta here.

I'd like to give a special thanks for @pouladpld for his pull request to get the ball rolling on this.

@FrankyBoy
Copy link
Contributor

Hi!

We are currently testing this. While this change allows us to explicitly set our path (eg. "/1.0/GraphQl"), I would argue this change would work better if this variable is an empty string (so that calls on the interface go to the same URL the interface is hosted on) or at least this check should be removed so we can manually do app.UseGraphiQl(""); if we want this behaviour.

Cheers

@FrankyBoy
Copy link
Contributor

Actually, digging deeper, the real problem is that GraphiQL treats the server and JS paths the same. If you have a setup in IIS like this ...
image
Then IIS strips the "1.0" out of the path. So from JS side your URL is /1.0/graphql while from C# side (i.e. in GraphiQlConfig or the FileServerOptions built here) the path should just be /graphql.

@josephwoodward
Copy link
Owner

josephwoodward commented Aug 21, 2018

Thanks for giving the beta try!

So from JS side your URL is /1.0/graphql while from C# side (i.e. in GraphiQlConfig or the FileServerOptions built here) the path should just be /graphql

I don't have IIS to hand as I use a Mac/Linux, any thoughts how we could resolve this? Not sure how we could get around IIS stripping values from the path, feels like that shouldn't be the responsibility of this library. Thoughts?

@FrankyBoy
Copy link
Contributor

Yes, I am absolutely with you, it's not your responsibility to know that. Obvious "worst case" solution is allowing setting of JS and C# paths separately, but that really isn't elegant.

@josephwoodward
Copy link
Owner

@FrankyBoy Though I'm wondering if there would be any use cases for adding an overload to enable you to configure the JS and C# paths separately. I'm not completely against the idea.

@FrankyBoy
Copy link
Contributor

FrankyBoy commented Aug 22, 2018

Other than my use case (i.e. IIS being weird) I see also this one: Having a separate configuration would make sense if someone wants to host the UI in a different location than the actual graphql endpoint. Like /docs for the interface and /graphql for the actual graphql endpoint. That would require different paths for the FileServerOptions and the path in the delivered JS as well. You could even target another server entirely (for instance to host a sort of centralized documentation site where you can switch between different services quickly).

Not sure if anyone would ever want to do that, it's just another potential use case I see.

@FrankyBoy
Copy link
Contributor

Any update here? Should I just push a change that lets us configure server and client path independently or can you look into the topic?

Cheers!

@josephwoodward
Copy link
Owner

josephwoodward commented Oct 19, 2018

1.2.0 has now been published to NuGet, I will now close this PR. If anyone has any issues then please feel free to reopen it.

@areyes21
Copy link

areyes21 commented Jul 8, 2019

In my solution works normally but when publish in IIS server show this empty string ""
imagen

@areyes21
Copy link

areyes21 commented Jul 8, 2019

In my Solution is fine, Which may be?
imagen

@josephwoodward
Copy link
Owner

@areyes21 That's odd. If you perform the query via a raw HTTP Request (as opposed to using GraphiQL), do you get any results? That would isolate the issue to this library.

Also, have you looked in your browser's dev tools? GraphiQL queries your API via an ajax request so it would seem that your API is returning no data?

Is the schema viewer working?

@areyes21
Copy link

areyes21 commented Jul 9, 2019

The route of graphqlpath is /GraphQL But if I change graphqlpath for an empty string it works well.

Line of code
imagen

imagen

imagen

@josephwoodward
Copy link
Owner

Is there any chance you'd be able to create a repo of this issue as I'm struggling to reproduce it?

Alternatively, what does your configuration look like? I see you're running it from localhost in your screenshots? Earlier you mentioned it was only when you published your app to IIS? (or does it also do it if you're running it via IIS locally?)

@areyes21
Copy link

Sorry I do not speak English but I will do my best to explain

@areyes21
Copy link

I could solve it, adding what I show in the screenshots (EN)
Lo pude resolver, agregando lo que le muestro en las capturas de pantalla (ES)

imagen

imagen

imagen

@areyes21
Copy link

Thanks for all the help, Greetings from Nicaragua

@josephwoodward
Copy link
Owner

I'm glad you got this sorted in the end, I'm going to mark this issue as closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants