Skip to content

Instantly share code, notes, and snippets.

@ddialar
Created May 3, 2018 06:22
Show Gist options
  • Save ddialar/fec4896c77d69660818a8d6916874899 to your computer and use it in GitHub Desktop.
Save ddialar/fec4896c77d69660818a8d6916874899 to your computer and use it in GitHub Desktop.
Phone Number type definition for GraphQL back-end.
import {
GraphQLObjectType,
GraphQLInputObjectType,
GraphQLString,
GraphQLNonNull
} from 'graphql';
var ObjectType = new GraphQLObjectType({
name: 'PhoneNumber',
fields: () => ({
number: { type: new GraphQLNonNull(GraphQLString) },
description: { type: GraphQLString }
})
});
var InputType = new GraphQLInputObjectType({
name: 'PhoneNumberInput',
fields: () => ({
number: { type: new GraphQLNonNull(GraphQLString) },
description: { type: GraphQLString }
})
});
export {
ObjectType,
InputType
};
@ddialar
Copy link
Author

ddialar commented Mar 29, 2021

With Apollo we use .graphql or .gql schema definitions.

If you pay attention to the code, I'm using the raw graphql library and this code is focused on being used with graphql-express. No one has mentioned Apollo any where.

As you surely already know, depending on the tool you use in order to implement your GraphQL server, the schema definition is going to be different.

This code only shows the most basic way that it existed three years ago. Obviously, to implement a server this way has no sense nowadays.

@ashishtz
Copy link

Thanks! I'm New in graphql so Haven't much Idea about it. Found your content for the phone number so I asked.

@ddialar
Copy link
Author

ddialar commented Mar 29, 2021

Just a suggestion, try to look for up-to-date content. The post where I used that gist was typed long time ago and related tasks are not done this way right now.

@ddialar
Copy link
Author

ddialar commented Mar 29, 2021

I've been checking and Apollo Server repository was create on April 17, 2016 and this gist code was created on August 27, 2017.

In that date Apollo Server was irrelevant yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment