在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):soundtrackyourbrand/graphql-custom-datetype开源软件地址(OpenSource Url):https://github.com/soundtrackyourbrand/graphql-custom-datetype开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):Custom Date Type for GraphQLThis is a custom date type implementation for GraphQL. GraphQL does not contain a native date type but it does allow you to specify custom scalar types that serializes to strings, or other scalar types, but conforms to certain standards. This date type accepts and outputs this format: '2015-07-24T13:15:34.814Z' which is commonly used in JSON since it is the default format used by JavaScript when serializing dates to JSON. UsageTo use this type you in your GraphQL schema you simply install this module with
The important part is that your resolve function needs to return a JavaScript Date object. // examples/now.js
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
} from 'graphql';
import CustomGraphQLDateType from '..';
let schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
now: {
type: CustomGraphQLDateType,
// Resolve fields with the custom date type to a valid Date object
resolve: () => new Date()
}
}
})
});
graphql(schema, "{ now }")
.then(console.log)
.catch(console.error); Running this prints the current date: $ babel-node examples/now.js
{ data: { now: '2015-07-24T13:23:15.580Z' } } |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论