Open albertly opened 3 years ago
I am trying to use graphql-constraint-directive with apollo graphql server. 1.
const typeDefs = gql` input ClaimInput { id: String! date: String! phone: String @constraint(pattern: "^05\d([-]{0,1})\d{7}$") email: String invoice: String doctorId: String therapy: [TherapyInput] files: [FileInput] } `
It didn't work for me. No match. Regular expression is correct. The sample works with this one @constraint(pattern: "^[0-9a-zA-Z]$")*.
So I realized that something wrong with ^05\d([-]{0,1})\d{7}$ in my template literal typeDefs.
When I've changed to: 2.
const typeDefs = gql` input ClaimInput { id: String! date: String! phone: String @constraint(pattern: "^05\\d([-]{0,1})\\d{7}$") email: String invoice: String doctorId: String therapy: [TherapyInput] files: [FileInput] } `
I've got an error: GraphQLError: Syntax Error: Invalid character escape sequence: \d.
3. When I've changed to
const typeDefsRaw = String.raw` input ClaimInput { id: String! date: String! phone: String @constraint(pattern: "^05\d([-]{0,1})\d{7}$") email: String invoice: String doctorId: String therapy: [TherapyInput] files: [FileInput] } ` const typeDefs = gql`${typeDefsRaw}`;
I've got the same error: GraphQLError: Syntax Error: Invalid character escape sequence: \d.
Is it a bug? Or how to deal with this situation?
Moving this to the graphql-tag repository.
graphql-tag
I am trying to use graphql-constraint-directive with apollo graphql server. 1.
It didn't work for me. No match. Regular expression is correct. The sample works with this one @constraint(pattern: "^[0-9a-zA-Z]$")*.
So I realized that something wrong with ^05\d([-]{0,1})\d{7}$ in my template literal typeDefs.
When I've changed to: 2.
I've got an error: GraphQLError: Syntax Error: Invalid character escape sequence: \d.
3. When I've changed to
I've got the same error: GraphQLError: Syntax Error: Invalid character escape sequence: \d.
Is it a bug? Or how to deal with this situation?