graphql#GraphQLInt TypeScript Examples
The following examples show how to use
graphql#GraphQLInt.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From proto2graphql with MIT License | 7 votes |
ScalarTypeMap = {
double: GraphQLFloat,
float: GraphQLFloat,
int32: GraphQLInt,
int64: GraphQLInt,
uint32: GraphQLInt,
uint64: GraphQLInt,
sint32: GraphQLInt,
sint64: GraphQLInt,
fixed32: GraphQLInt,
fixed64: GraphQLInt,
sfixed32: GraphQLInt,
sfixed64: GraphQLInt,
bool: GraphQLBoolean,
string: GraphQLString,
bytes: GraphQLString
}
Example #2
Source File: isRequired.test.ts From amplify-codegen with Apache License 2.0 | 6 votes |
describe('isRequired', () => {
const testObj = new GraphQLInputObjectType({
name: 'Address',
fields: {
street: { type: GraphQLString },
requiredInt: { type: new GraphQLNonNull(GraphQLInt) },
},
});
it('should return false for null types', () => {
expect(isRequired(testObj.getFields().street.type)).toEqual(false);
});
it('should return true for non null types', () => {
expect(isRequired(testObj.getFields().requiredInt.type)).toEqual(true);
});
});
Example #3
Source File: GraphqlTypeInterpreter.ts From aloxide with Apache License 2.0 | 6 votes |
interpret(input: FieldTypeEnum): GraphQLScalarType {
let type: GraphQLScalarType;
switch (input) {
case FieldTypeEnum.uint16_t:
case FieldTypeEnum.uint32_t:
case FieldTypeEnum.uint64_t:
type = GraphQLInt;
break;
case FieldTypeEnum.number:
case FieldTypeEnum.double:
type = GraphQLFloat;
break;
case FieldTypeEnum.bool:
type = GraphQLBoolean;
break;
case FieldTypeEnum.account:
case FieldTypeEnum.string:
type = GraphQLString;
break;
default:
throw new Error(`unknow type ${type}`);
}
return type;
}
Example #4
Source File: GraphqlTypeInterpreter.test.ts From aloxide with Apache License 2.0 | 6 votes |
describe('test GraphqlTypeInterpreter', () => {
describe('interpret()', () => {
const intepreter = new GraphqlTypeInterpreter();
it('should throw error when Field Type is not support', () => {
expect(() => {
// @ts-ignore
intepreter.interpret('not supported type');
}).toThrowError('unknow type');
});
it('should return Graphql Int when the input is uint', () => {
expect(intepreter.interpret(FieldTypeEnum.uint16_t)).toBe(GraphQLInt);
expect(intepreter.interpret(FieldTypeEnum.uint32_t)).toBe(GraphQLInt);
expect(intepreter.interpret(FieldTypeEnum.uint64_t)).toBe(GraphQLInt);
});
it('should return Graphql Float when the input is number or double', () => {
expect(intepreter.interpret(FieldTypeEnum.number)).toBe(GraphQLFloat);
expect(intepreter.interpret(FieldTypeEnum.double)).toBe(GraphQLFloat);
});
it('should return Graphql Boolean when the input is boolean', () => {
expect(intepreter.interpret(FieldTypeEnum.bool)).toBe(GraphQLBoolean);
});
it('should return Graphql String when the input is string', () => {
expect(intepreter.interpret(FieldTypeEnum.account)).toBe(GraphQLString);
expect(intepreter.interpret(FieldTypeEnum.string)).toBe(GraphQLString);
});
});
});
Example #5
Source File: getType.test.ts From amplify-codegen with Apache License 2.0 | 6 votes |
describe('getType', () => {
const testObj = new GraphQLObjectType({
name: 'Address',
fields: {
street: { type: GraphQLString },
number: { type: GraphQLInt },
requiredInt: { type: new GraphQLNonNull(GraphQLInt) },
listOfInt: { type: new GraphQLList(GraphQLInt) },
listOfNonNullInt: { type: new GraphQLNonNull(new GraphQLList(GraphQLInt)) },
},
});
it('should return string type for street', () => {
expect(getType(testObj.getFields().street.type)).toEqual(GraphQLString);
});
it('should return integer type for number', () => {
expect(getType(testObj.getFields().number.type)).toEqual(GraphQLInt);
});
it('should return integer type for a Non-Null integer', () => {
expect(getType(testObj.getFields().requiredInt.type)).toEqual(GraphQLInt);
});
it('should return integer type for list of integer type', () => {
expect(getType(testObj.getFields().listOfInt.type)).toEqual(GraphQLInt);
});
it('should return integer type for a list of non null integer type', () => {
expect(getType(testObj.getFields().listOfNonNullInt.type)).toEqual(GraphQLInt);
});
});
Example #6
Source File: buildPaginatedListType.ts From payload with MIT License | 6 votes |
buildPaginatedListType = (name, docType) => new GraphQLObjectType({
name,
fields: {
docs: {
type: new GraphQLList(docType),
},
totalDocs: { type: GraphQLInt },
offset: { type: GraphQLInt },
limit: { type: GraphQLInt },
totalPages: { type: GraphQLInt },
page: { type: GraphQLInt },
pagingCounter: { type: GraphQLInt },
hasPrevPage: { type: GraphQLBoolean },
hasNextPage: { type: GraphQLBoolean },
prevPage: { type: GraphQLBoolean },
nextPage: { type: GraphQLBoolean },
},
})
Example #7
Source File: buildMutationInputType.ts From payload with MIT License | 6 votes |
getCollectionIDType = (config: SanitizedCollectionConfig): GraphQLScalarType => {
const idField = config.fields.find((field) => fieldAffectsData(field) && field.name === 'id');
if (!idField) return GraphQLString;
switch (idField.type) {
case 'number':
return GraphQLInt;
default:
return GraphQLString;
}
}
Example #8
Source File: setting.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
limit: number
Example #9
Source File: schema.ts From apollo-server-vercel with MIT License | 5 votes |
queryType = new GraphQLObjectType({
name: `QueryType`,
fields: {
testString: {
type: GraphQLString,
resolve(): string {
return `it works`;
}
},
testPerson: {
type: personType,
resolve(): { firstName: string; lastName: string } {
return { firstName: `Jane`, lastName: `Doe` };
}
},
testStringWithDelay: {
type: GraphQLString,
args: {
delay: { type: new GraphQLNonNull(GraphQLInt) }
},
async resolve(_, args): Promise<string> {
return new Promise((resolve) => {
setTimeout(() => resolve(`it works`), args.delay);
});
}
},
testContext: {
type: GraphQLString,
resolve(_parent, _args, context): string {
if (context.otherField) {
return `unexpected`;
}
context.otherField = true;
return context.testField;
}
},
testRootValue: {
type: GraphQLString,
resolve(rootValue): typeof rootValue {
return rootValue;
}
},
testArgument: {
type: GraphQLString,
args: { echo: { type: GraphQLString } },
resolve(_, { echo }): string {
return `hello ${String(echo)}`;
}
},
testError: {
type: GraphQLString,
resolve(): void {
throw new Error(`Secret error message`);
}
}
}
})
Example #10
Source File: form.field.rating.input.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt, { nullable: true })
readonly steps: number
Example #11
Source File: form.field.rating.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt, { nullable: true })
readonly steps: number
Example #12
Source File: form.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
total: number
Example #13
Source File: form.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
limit: number
Example #14
Source File: form.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
start: number
Example #15
Source File: setting.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
total: number
Example #16
Source File: user.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
start: number
Example #17
Source File: setting.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
start: number
Example #18
Source File: scalars.ts From squid with GNU General Public License v3.0 | 5 votes |
Int = GraphQLInt
Example #19
Source File: submission.statistic.resolver.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@ResolveField(() => GraphQLInt)
@Roles('admin')
total(): Promise<number> {
return this.statisticService.getTotal()
}
Example #20
Source File: submission.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
total: number
Example #21
Source File: submission.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
limit: number
Example #22
Source File: submission.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
start: number
Example #23
Source File: user.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
total: number
Example #24
Source File: user.pager.model.ts From api with GNU Affero General Public License v3.0 | 5 votes |
@Field(() => GraphQLInt)
limit: number
Example #25
Source File: schema_builder.ts From graphql-mesh with MIT License | 5 votes |
/**
* Returns the GraphQL scalar type matching the given JSON schema type
*/
function getScalarType<TSource, TContext, TArgs>({
def,
data,
}: CreateOrReuseSimpleTypeParams<TSource, TContext, TArgs>): GraphQLScalarType {
switch (def.targetGraphQLType) {
case 'id':
def.graphQLType = GraphQLID;
break;
case 'string':
def.graphQLType = GraphQLString;
break;
case 'integer':
def.graphQLType = GraphQLInt;
break;
case 'int64':
def.graphQLType = GraphQLBigInt;
break;
case 'number':
def.graphQLType = GraphQLFloat;
break;
case 'float':
def.graphQLType = GraphQLFloat;
break;
case 'boolean':
def.graphQLType = GraphQLBoolean;
break;
case 'json':
def.graphQLType = GraphQLJSON;
break;
case 'dateTime':
def.graphQLType = GraphQLDateTime;
break;
default:
throw new Error(`Cannot process schema type '${def.targetGraphQLType}'.`);
}
return def.graphQLType as GraphQLScalarType;
}
Example #26
Source File: week.ts From peterportal-public-api with MIT License | 5 votes |
weekType: GraphQLObjectType = new GraphQLObjectType({
name: 'Week',
fields: () => ({
week: { type: GraphQLInt, description: "School week between 1-10" },
quarter: { type: GraphQLString, description: "Quarter and year" },
display: { type: GraphQLString, description: "Displays the week and quarter formatted" }
})
})
Example #27
Source File: typeNameFromGraphQLType.ts From amplify-codegen with Apache License 2.0 | 5 votes |
describe('Swift code generation: Types', () => {
let helpers: Helpers;
beforeEach(() => {
helpers = new Helpers({});
});
describe('#typeNameFromGraphQLType()', () => {
it('should return String? for GraphQLString', () => {
expect(helpers.typeNameFromGraphQLType(GraphQLString)).toBe('String?');
});
it('should return String for GraphQLNonNull(GraphQLString)', () => {
expect(helpers.typeNameFromGraphQLType(new GraphQLNonNull(GraphQLString))).toBe('String');
});
it('should return [String?]? for GraphQLList(GraphQLString)', () => {
expect(helpers.typeNameFromGraphQLType(new GraphQLList(GraphQLString))).toBe('[String?]?');
});
it('should return [String?] for GraphQLNonNull(GraphQLList(GraphQLString))', () => {
expect(helpers.typeNameFromGraphQLType(new GraphQLNonNull(new GraphQLList(GraphQLString)))).toBe('[String?]');
});
it('should return [String]? for GraphQLList(GraphQLNonNull(GraphQLString))', () => {
expect(helpers.typeNameFromGraphQLType(new GraphQLList(new GraphQLNonNull(GraphQLString)))).toBe('[String]?');
});
it('should return [String] for GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLString)))', () => {
expect(helpers.typeNameFromGraphQLType(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))))).toBe('[String]');
});
it('should return [[String?]?]? for GraphQLList(GraphQLList(GraphQLString))', () => {
expect(helpers.typeNameFromGraphQLType(new GraphQLList(new GraphQLList(GraphQLString)))).toBe('[[String?]?]?');
});
it('should return [[String?]]? for GraphQLList(GraphQLNonNull(GraphQLList(GraphQLString)))', () => {
expect(helpers.typeNameFromGraphQLType(new GraphQLList(new GraphQLNonNull(new GraphQLList(GraphQLString))))).toBe('[[String?]]?');
});
it('should return Int? for GraphQLInt', () => {
expect(helpers.typeNameFromGraphQLType(GraphQLInt)).toBe('Int?');
});
it('should return Double? for GraphQLFloat', () => {
expect(helpers.typeNameFromGraphQLType(GraphQLFloat)).toBe('Double?');
});
it('should return Bool? for GraphQLBoolean', () => {
expect(helpers.typeNameFromGraphQLType(GraphQLBoolean)).toBe('Bool?');
});
it('should return GraphQLID? for GraphQLID', () => {
expect(helpers.typeNameFromGraphQLType(GraphQLID)).toBe('GraphQLID?');
});
it('should return String? for a custom scalar type', () => {
expect(helpers.typeNameFromGraphQLType(new GraphQLScalarType({ name: 'CustomScalarType', serialize: String }))).toBe('String?');
});
it('should return a passed through custom scalar type with the passthroughCustomScalars option', () => {
helpers.options.passthroughCustomScalars = true;
helpers.options.customScalarsPrefix = '';
expect(helpers.typeNameFromGraphQLType(new GraphQLScalarType({ name: 'CustomScalarType', serialize: String }))).toBe(
'CustomScalarType?'
);
});
it('should return a passed through custom scalar type with a prefix with the customScalarsPrefix option', () => {
helpers.options.passthroughCustomScalars = true;
helpers.options.customScalarsPrefix = 'My';
expect(helpers.typeNameFromGraphQLType(new GraphQLScalarType({ name: 'CustomScalarType', serialize: String }))).toBe(
'MyCustomScalarType?'
);
});
});
});
Example #28
Source File: types.ts From amplify-codegen with Apache License 2.0 | 5 votes |
builtInScalarMap = {
[GraphQLString.name]: 'string',
[GraphQLInt.name]: 'number',
[GraphQLFloat.name]: 'number',
[GraphQLBoolean.name]: 'boolean',
[GraphQLID.name]: 'string',
}
Example #29
Source File: helpers.ts From amplify-codegen with Apache License 2.0 | 5 votes |
builtInScalarMap = {
[GraphQLString.name]: 'String',
[GraphQLInt.name]: 'Int',
[GraphQLFloat.name]: 'Double',
[GraphQLBoolean.name]: 'Bool',
[GraphQLID.name]: 'GraphQLID',
}