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

Omit field when using derive GraphQLObject #220

Closed
sporto opened this issue Aug 13, 2018 · 1 comment
Closed

Omit field when using derive GraphQLObject #220

sporto opened this issue Aug 13, 2018 · 1 comment
Assignees
Labels
enhancement Improvement of existing features or bugfix

Comments

@sporto
Copy link
Contributor

sporto commented Aug 13, 2018

I have a struct like (which doubles as a diesel model):

#[derive(Queryable, GraphQLObject, Debug)]
pub struct User {
	pub id: i32,
	pub email: String,
	pub password_hash: String,
	...
}

I would like to omit password_hash in the generated GraphQl type.
Is this possible at the moment or do I have to create another Struct?
A way of omitting some fields would be great.

Thanks.

@sporto sporto changed the title Hide attr when using derive GraphQLObject Omit field when using derive GraphQLObject Aug 13, 2018
@piperRyan
Copy link
Contributor

piperRyan commented Aug 14, 2018

While there isn't a way to omit a field like serde's skip_serializing , but I think one should be able to do this like so:

#[derive(Queryable, Debug)]
pub struct User {
	pub id: i32,
	pub email: String,
	pub password_hash: String,
	...
}

graphql_object!(User: () |&self| {
    description: "A user in the database"

    field id() -> &i32 as "The user's unique identifier" {
        &self.id
    }

    field email() -> &String as "The user's email" {
        &self.email
    }

   ... other fields to expose leaving out password_hash
});

However, I have to admit I haven't tried this.

LegNeato added a commit to LegNeato/juniper that referenced this issue Aug 16, 2018
Fields can now be skipped with the `#[graphql(skip)]` annotation. Note this
doesn't really make sense for GraphQLInputObjects so this isn't supported there.

Fixes graphql-rust#220.
@LegNeato LegNeato self-assigned this Aug 16, 2018
@LegNeato LegNeato added the enhancement Improvement of existing features or bugfix label Aug 16, 2018
LegNeato added a commit to LegNeato/juniper that referenced this issue Aug 19, 2018
Fields can now be skipped with the `#[graphql(skip)]` annotation. Note this
doesn't really make sense for GraphQLInputObjects so this isn't supported there.

Fixes graphql-rust#220.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix
Projects
None yet
Development

No branches or pull requests

3 participants