Exemple #1
0
def augmented_schema_cypher_test_runner(self,
                                        graphql_query,
                                        expected_cypher_query,
                                        params=None):
    def resolve_query(_, info, **kwargs):
        query = cypher_query(info.context, info, **kwargs)
        self.assertEqual(first=expected_cypher_query, second=query)

    resolvers = {
        'Query': {
            'Movie': resolve_query,
            'MoviesByYear': resolve_query,
            'MovieById': resolve_query,
            'MovieBy_Id': resolve_query,
            'GenresBySubstring': resolve_query,
            'Books': resolve_query,
        }
    }

    schema = make_executable_schema(test_schema, resolvers)
    aug_schema = augment_schema(schema)

    # query the test schema with the test query, assertion is in the resolver
    return graphql_sync(aug_schema,
                        graphql_query,
                        variable_values=params,
                        context_value=mock.MagicMock())
Exemple #2
0
def test_runner(self, graphql_query, expected_cypher_query, params=None):
    test_movie_schema = test_schema + '''
    type Mutation {
        CreateGenre(name: String): Genre @cypher(statement: "CREATE (g:Genre) SET g.name = $name RETURN g")
        CreateMovie(movieId: ID!, title: String, year: Int, plot: String, poster: String, imdbRating: Float): Movie
        AddMovieGenre(moviemovieId: ID!, genrename: String): Movie @MutationMeta(relationship: "IN_GENRE", from:"Movie", to:"Genre")
    }
    '''

    def resolve_query(_, info, **kwargs):
        query = cypher_query(info.context, info, **kwargs)
        self.assertEqual(first=expected_cypher_query, second=query)

    def resolve_mutation(_, info, **kwargs):
        query = cypher_mutation(info.context, info, **kwargs)
        self.assertEqual(first=expected_cypher_query, second=query)

    resolvers = {
        'Query': {
            'Movie': resolve_query,
            'MoviesByYear': resolve_query,
            'MovieById': resolve_query,
            'MovieBy_Id': resolve_query,
            'GenresBySubstring': resolve_query,
            'Books': resolve_query,
        },
        'Mutation': {
            'CreateGenre': resolve_mutation,
            'CreateMovie': resolve_mutation,
            'AddMovieGenre': resolve_mutation,
        }
    }

    schema = make_executable_schema(test_movie_schema, resolvers)

    # query the test schema with the test query, assertion is in the resolver
    return graphql_sync(schema, graphql_query, variable_values=params)
Exemple #3
0
}
'''

resolvers = {
    # root entry point to GraphQL service
    'Query': {
        'Movie':
        lambda obj, info, **kwargs: neo4j_graphql(obj, info.context, info, **
                                                  kwargs),
        'MoviesByYear':
        lambda obj, info, **kwargs: neo4j_graphql(obj, info.context, info, **
                                                  kwargs)
    }
}

schema = make_executable_schema(typeDefs, resolvers)

driver = None


def context(request):
    global driver
    if driver is None:
        driver = neo4j.GraphDatabase.driver("bolt://localhost:7687",
                                            auth=("neo4j", "neo4j123"))

    return {'driver': driver, 'request': request}


root_value = {}
app = GraphQL(schema=schema,
Exemple #4
0
def augmented_schema():
    schema = make_executable_schema(test_schema, resolvers=[])
    aug_schema = augment_schema(schema)
    return aug_schema