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

GraphQLNonNull and empty strings #480

Closed
jsonmaur opened this issue Sep 7, 2016 · 3 comments
Closed

GraphQLNonNull and empty strings #480

jsonmaur opened this issue Sep 7, 2016 · 3 comments

Comments

@jsonmaur
Copy link

jsonmaur commented Sep 7, 2016

I assumed that if I have an argument with type new GraphQLNonNull(GraphQLString), it would not allow empty strings. But it seems this is not the case. Is there another way to make sure empty strings are caught for required arguments?

@stubailo
Copy link
Contributor

stubailo commented Sep 8, 2016

Currently GraphQL doesn't handle form-style validation, like ensuring the length of a string (an empty string is definitely not null, especially in JavaScript).

You might be interested in this thread, which talks about using custom input types for validation like this: #361

@jsonmaur
Copy link
Author

jsonmaur commented Sep 8, 2016

Yeah that's what I thought. Thanks, I'll keep an eye on that thread.

@jsonmaur jsonmaur closed this as completed Sep 8, 2016
@Cuantico
Copy link

Cuantico commented Feb 18, 2020

In the model do it like this:

const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const buinessSchema = new Schema({
  name: { type: String, required: true, unique: true },
  address: { type: String, required: true },
  phone: { type: String, required: true },
  email: { type: String, required: true },
  website: { type: String, required: true },
  currency: { type: String, required: true },
  aboutus: { type: String, required: true },
  terms: String,
  slogan: String,
  logo: { type: String, required: true }
});

module.exports = mongoose.model("Buiness", buinessSchema);

that will include both null and empty strings

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

3 participants