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

Option to specify custom mutation query name #445

Closed
chandu0101 opened this issue Oct 9, 2015 · 4 comments
Closed

Option to specify custom mutation query name #445

chandu0101 opened this issue Oct 9, 2015 · 4 comments

Comments

@chandu0101
Copy link
Contributor

Hi,
Scala.js-relay mutation queries not working because of this reason graphql/graphql-spec#102

i don't see any activity from graphql side may be it requires more work!, In my understanding graphql should allow javascript valid identifiers as its not the case now and scala.js can't do anything either so is it possible to allow option( static queryName) to define mutation query names ? or can we modify query name to match graphql ASCII set before sending ?

please let me know if either of cases can possible ? , i am happy to send a PR!

@josephsavona
Copy link
Contributor

Mutations can specify a custom name with Relay.QLmutation YourNameHere { ... }`` - does this help?

@xsistens
Copy link

xsistens commented Oct 9, 2015

@josephsavona is the code you referring to the one from the getMutation method like in this example?

class LikeStoryMutation extends Relay.Mutation {
  getMutation() {
    return this.props.story.viewerDoesLike
      return Relay.QL`mutation MutationName {likeStory}`;
  }
}

if yes, then this does not solve the problem.
@chandu0101 is talking about the mutation name that is actually used in the query that is send to the graphql server.

As an example from scala.js relay version we developed, the query looks like this, even after applying the change you suggested:

mutation $c_Lcom_scalajs_relay_examples_treasure_mutations_CheckHidingSpotForTreasureMutation($input_0:CheckHidingSpotForTreasureInput!){
  checkHidingSpotForTreasure(input:$input_0){
    clientMutationId,
    ...
  }
}

as you can see in scala.js it still has a weird name, that indicates me that the name that is used in the query is generated of the name from the actual mutation instance in the global namespace (just a guess). In scala.js this must be unique over the whole javascript libraries that are used, thats why the package name is used. If your suggestion would affect the name used in the query i guess it should be reflected somewhere in this path even in scala.js. but i'm not 100% certain.

@josephsavona
Copy link
Contributor

@xsistens Thanks for providing more detail, I see what's happening.

It seems reasonable to use the name of the mutation (from the Relay.QLmutation YourName {...}``) as the name that is sent to the server. Note that babel-relay-plugin defaults to using the filename when no mutation name is provided in the query, so the default behavior shouldn't change (we should confirm). The change would be in RelayMutationTransaction - we can replace `this._mutation.constructor.name` with `this._getMutationNode().name`. Want to submit a PR? ;-)

@chandu0101
Copy link
Contributor Author

@josephsavona thanks alot for pointer , i just opened a PR #448 please review it , i can confirm that scalajs mutations working fine now 👍

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

Successfully merging a pull request may close this issue.

3 participants