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

How do you define descriptions using type definitions? #100

Closed
petebrowne opened this issue Aug 9, 2016 · 12 comments
Closed

How do you define descriptions using type definitions? #100

petebrowne opened this issue Aug 9, 2016 · 12 comments

Comments

@petebrowne
Copy link

It's not clear how to define type/args descriptions using type definitions - or if it is even possible.

For instance, using vanilla graphql-js:

export const User = new GraphQLObjectType({
  name: 'User',
  description: 'A user with an account.'
  fields: () => ({
    username: {
      type: new GraphQLNonNull(GraphQLString),
      description: 'A unique name for the user'
    },
  })
});

I expected this to add descriptions, but it doesn't:

export const schema = [`
# A user with an account.
type User {
  # A unique name for the user.
  username: String!
}
`];
@helfer
Copy link
Contributor

helfer commented Aug 9, 2016

@petebrowne I agree 100% that it would be much nicer to have comments turn into descriptions. The reason it doesn't is that we use the parser from graphql-js, and that parser doesn't support it yet. The best way to get it to happen is probably to put your voice behind this PR (or a modified version thereof): graphql/graphql-js#427

@helfer
Copy link
Contributor

helfer commented Aug 9, 2016

And to answer your question on how to do this with graphql-tools currently: you have to pass the descriptions in resolvers like so:

const resolvers = {
  User: {
    __description: "A user with an account",
    username: {
      description: "A unique name for the user",
      resolve: user => user.username,
    }
  }
};

Please note that for types you have to use __description while for fields you just use description.

@petebrowne
Copy link
Author

Thanks for the info! I'll follow the graphql-js parser for updates.

@helfer
Copy link
Contributor

helfer commented Aug 28, 2016

@peterbrowne: guess what, descriptions just landed in graphql-js 0.7.0.

@helfer helfer closed this as completed Aug 28, 2016
@stubailo
Copy link
Contributor

@helfer does graphql-tools support the feature now?

@helfer
Copy link
Contributor

helfer commented Aug 29, 2016

Yep, sure does!

@tonyxiao
Copy link

tonyxiao commented Sep 9, 2016

@helfer @stubailo I can't find any docs on how to use the description still. Mind pointing me to the right place?

@stubailo
Copy link
Contributor

stubailo commented Sep 9, 2016

Just put a comment in the schema above the relevant field. We don't have docs for it yet.

@tonyxiao
Copy link

tonyxiao commented Sep 9, 2016

Hmm that's exactly what I tried though. But doesn't seem to work. I'm using "graphql-tools": "^0.6.6", should be correct?

image

@DxCx
Copy link
Contributor

DxCx commented Sep 9, 2016

Hi @tonyxiao,
Looking at @helfer 's medium post
That is correct (single hashtag)
Are you using graphql-js v 0.7.0?

@tonyxiao
Copy link

tonyxiao commented Sep 9, 2016

@DxCx Oh sweet, thanks for the pointer. I assumed that I needed to upgrade graphql-tools, but turns out I actually need to upgrade graphql instead (peerDependency of graphql-tools). Upgraded and working, thanks!

@DxCx
Copy link
Contributor

DxCx commented Sep 9, 2016

great @tonyxiao happy to hear it as i didn't had to the time to test it myself, so i assume we can close this issue =)

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

5 participants