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

Docs: type definitions with apollo gql template literal #37

Open
aichbauer opened this issue Jan 11, 2019 · 0 comments
Open

Docs: type definitions with apollo gql template literal #37

aichbauer opened this issue Jan 11, 2019 · 0 comments

Comments

@aichbauer
Copy link
Owner

Right now we define our types with JavaScript and I do not plan on changing this in this project since, I like writing everything in the same language. But with gql template literals we have also a way to create our types. It is not a way I really like, but since it is possible with this project and very popular to create your types this way we should definitively document this way, also because it is very easy to switch.

Instead of:

const UserType = new GraphQLObjectType({
  name: 'User',
  description: 'This represents a User',
  fields: () => ({
    id: {
      type: GraphQLInt,
      resolve: (user) => user.id,
    },
  }),
});

you can write something similar to:

const typeDefs = gql`
  type UserType {
    "This represents a User"
    id: Int
  }
`;

const resolvers = {
  UserType: {
    id: (user) => user.id
  }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant