How to use the GraphQLScalarType function from graphql

Find comprehensive JavaScript graphql.GraphQLScalarType code examples handpicked from public code repositorys.

12
13
14
15
16
17
18
19
20
21
22
    ASC: { value: 'ASC' },
    DESC: { value: 'DESC' }
  }
})


const limitType = new graphql.GraphQLScalarType({
  name: 'LimitInt',
  description: 'Limit will be applied by default if not passed. If the provided value exceeds the maximum allowed value a validation error will be thrown'
})

fork icon85
star icon888
watch icon16

+ 32 other calls in file

1
2
3
4
5
6
7
8
9
10
const assert = require('assert');
const _ = require('lodash');

const InputObjectType = graphql.GraphQLInputObjectType;
const InterfaceType = graphql.GraphQLInterfaceType;
const ScalarType = graphql.GraphQLScalarType;
const ObjectType = graphql.GraphQLObjectType;
const UnionType = graphql.GraphQLUnionType;
const NonNullType = graphql.GraphQLNonNull;
const EnumType = graphql.GraphQLEnumType;
fork icon13
star icon203
watch icon10

+ 3 other calls in file

36
37
38
39
40
41
42
43
44
});

test("prints type relations", () => {
  expect.hasAssertions();

  const type = new GraphQLScalarType({
    name: "String",
    description: "Lorem Ipsum",
  });
fork icon25
star icon107
watch icon0

+ 214 other calls in file

100
101
102
103
104
105
106
107
108
});

test("returns empty string if not enum type", () => {
  expect.hasAssertions();

  const scalarType = new GraphQLScalarType({
    name: "ScalarTypeName",
    type: GraphQLInt,
  });
fork icon25
star icon107
watch icon0

62
63
64
65
66
67
68
69
70
71
    || isNonNullType(type)
  );
}

function isScalarType(type) {
  return type instanceof gql.GraphQLScalarType;
}
function isObjectType(type) {
  return type instanceof gql.GraphQLObjectType;
}
fork icon7
star icon43
watch icon3

+ 9 other calls in file

41
42
43
44
45
46
47
48
49
50
//Below function is a GraphQL scalar that defines a valid Date.
//Serialize is used to send back/return a date in string format.
//ParseValue is used to convert all input values that are provided as an input JS variable.
//ParseLiteral is used to convert all input values that are in Int, String, etc. to a JSON-like form that GraphQL understands.
*/
const GraphQLDate = new GraphQLScalarType({
  name: 'GraphQLDate',
  description: 'A Date() type in GraphQL as a scalar',
  serialize(value) {
    return value.toISOString();
fork icon1
star icon1
watch icon1

+ 16 other calls in file

26
27
28
29
30
31
32
33
34
35
    description: "A valid date object",
    serialize: validate,
    parseValue: validate,
    parseLiteral,
};
const GraphQLDate = new graphql_1.GraphQLScalarType(GraphQLDateConfig);
const verifyCreateLessonInput = ({ title, category, meta, video, startDate, endDate, }) => {
    if (title.length > 160) {
        throw new Error("Title must not exceed 160 characters in length!");
    }
fork icon0
star icon0
watch icon1

+ 24 other calls in file

12
13
14
15
16
17
18
19
20
21
22
23
24
];






//resolvers
const GraphQLDate=new GraphQLScalarType({name:'GraphqlDate',description:'To retrieve the date in string format i serialize it',serialize(val){return val.toISOString();},
parseValue(value) {
  const dateValue = new Date(value); return isNaN(dateValue) ? undefined : dateValue; },
parseLiteral(ast) {
  if (ast.kind == Kind.STRING) { const value = new Date(ast.value); return isNaN(value) ? undefined : value; }
fork icon0
star icon0
watch icon1

+ 96 other calls in file

45
46
47
48
49
50
            type: 'string',
            pattern: regexp.source,
        },
    },
};
exports.GraphQLAccountNumber = new graphql_1.GraphQLScalarType(exports.GraphQLAccountNumberConfig);
fork icon0
star icon0
watch icon1

+ 24 other calls in file

29
30
31
32
33
34
35
36
37
38
                }
                : undefined);
        }
    }
};
exports.GraphQLTimeZone = new graphql_1.GraphQLScalarType({
    name: 'TimeZone',
    description: 'A field whose value exists in the standard IANA Time Zone Database: https://www.iana.org/time-zones',
    serialize: validateTimeZone,
    parseValue: validateTimeZone,
fork icon0
star icon0
watch icon1

+ 24 other calls in file

25
26
27
28
29
30
31
32
33
34
    if (!isCalendarDate) {
        throw (0, error_js_1.createGraphQLError)(`Value is not a valid LocalDate: ${value}`, ast ? { nodes: ast } : undefined);
    }
    return value;
}
exports.GraphQLLocalDate = new graphql_1.GraphQLScalarType({
    name: 'LocalDate',
    description: 'A local date string (i.e., with no associated timezone) in `YYYY-MM-DD` format, e.g. `2020-01-01`.',
    serialize(value) {
        // value sent to client as string
fork icon0
star icon0
watch icon1

+ 17 other calls in file

72
73
74
75
76
77
            type: 'string',
            format: 'byte',
        },
    },
};
exports.GraphQLByte = new graphql_1.GraphQLScalarType(exports.GraphQLByteConfig);
fork icon0
star icon0
watch icon1

+ 17 other calls in file

791
792
793
794
795
796
797
798
799
800
            {"username": args["username"]}, 
            {$set: {"admin": args["isAdmin"]}}
        );
    }
},
StringOrFloat: new GraphQLScalarType({
    name: "StringOrFloat",
    description: "A String or a Float union type",
    serialize(value) {
      if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
fork icon0
star icon0
watch icon5

+ 38 other calls in file

36
37
38
39
40
41
42
43
44
45
46
  setGreetingMessage(message: String!): String
  employeeAdd(employee: employeeInputs!): Employee!
}
`;


// const dateScalar = new GraphQLScalarType({
//   name: "Date",
//   description: "Date custom scalar type",
//   serialize(value) {
//     return value.toISOString().substring(0, 10); // Convert outgoing Date to integer for JSON
fork icon0
star icon0
watch icon1

+ 62 other calls in file

35
36
37
38
39
40
41
42
43
44
const { GraphQLScalarType } = require("graphql");
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const { fileRenamer } = require("../utils/helpers");
const resolvers = {
    Date: new GraphQLScalarType({
        name: "Date",
        description: "Date custom scalar type",
        serialize(value) {
            return value.toISOString().slice(0, 10);
fork icon0
star icon0
watch icon1

+ 10 other calls in file

11
12
13
14
15
16
17
18
19
20
    if (!IPv4_js_1.IPV4_REGEX.test(value) && !IPv6_js_1.IPV6_REGEX.test(value)) {
        throw (0, error_js_1.createGraphQLError)(`Value is not a valid IPv4 or IPv6 address: ${value}`, ast ? { nodes: ast } : undefined);
    }
    return value;
};
exports.GraphQLIP = new graphql_1.GraphQLScalarType({
    name: `IP`,
    description: `A field whose value is either an IPv4 or IPv6 address: https://en.wikipedia.org/wiki/IP_address.`,
    serialize(value) {
        return validate(value);
fork icon0
star icon0
watch icon1

+ 12 other calls in file

10
11
12
13
14
15
16
17
18
19
    if (!exports.IPV6_REGEX.test(value)) {
        throw (0, error_js_1.createGraphQLError)(`Value is not a valid IPv6 address: ${value}`, ast ? { nodes: ast } : undefined);
    }
    return value;
};
exports.GraphQLIPv6 = new graphql_1.GraphQLScalarType({
    name: `IPv6`,
    description: `A field whose value is a IPv6 address: https://en.wikipedia.org/wiki/IPv6.`,
    serialize(value) {
        return validate(value);
fork icon0
star icon0
watch icon1

+ 3 other calls in file

281
282
283
284
285
286
287
288
289
290
    variableDefinitions,
    argumentNodes
  };
}
const rawField = 'raw';
const RawScalar = new graphql.GraphQLScalarType({
  name: 'RawThingPlsDontRelyOnThisAnywhere'
});
const ReturnRawValueObjectType = new graphql.GraphQLObjectType({
  name: 'ReturnRawValue',
fork icon0
star icon0
watch icon1

+ 8 other calls in file